0

I want my URL to look like this:

https://example-test.example.com/example-application_1.1/index.php?page=pagename&action=actionname

But the user should only type:

https://example-test.example.com/example-application_1.1/pagename/actionname/

Is it possible to make this run with a RewriteRule in .htaccess? I couldn't figure it out.

My .htaccess-file looks like this at the moment:

RewriteEngine on

RewriteBase /

RewriteCond %{HTTP_HOST} ^example-test\.example\.com
RewriteRule ^example-application_1\.1/([^/]+)/([^/]+)/?$ /example-application_1\.1/index.php?page=$1&action=$2 [QSA,L]

3 Answers3

1

I did it:

RewriteEngine On

RewriteRule "^([^/]+)/([^/]+)/([^/]+)" index.php?page=$1&action=$2&$3 [L]
RewriteRule "^([^/]+)/([^/]+)/" index.php?page=$1&action=$2 [L]

So if the user types in this:

https://example-prefix.example.com/pagename/actionname/id=123&category=456

The URL will be turned into this:

https://example-prefix.example.com/index.php?page=pagename&action=actionname&id=123&category=456

If you still want to have access on your files simply do this:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)/([^/]+)" index.php?page=$1&action=$2&$3 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)/" index.php?page=$1&action=$2 [L]
0
RewriteEngine on
RewriteRule ^example-application_1.1/([^/]*)/([^/]*)/$ /example-application_1.1/?page=$1&action=$2 [L]

This should work.

In index.php, you can get variable: $_GET['page'] & $_GET['action'].

0

I think you can use:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)" index.php?page=$1&action=$2 [L]
ramin ashrafimanesh
  • 1,002
  • 10
  • 13