Reputation: 10667
I want to mask the URL http://example.com/index.php?path=controller/function
to http://example.com/controller/function
. function
isn't required to be present.
How can I do this with an htaccess file?
The following isn't working.
RewriteRule ^/?assets/(.*)$ assets/$1 [L] # directory for CSS, images, and JavaScript
RewriteRule ^$ /index [redirect]
RewriteRule ^([a-zA-Z]+)/?([a-zA-Z/]*)$ index.php?path=$1/$2 [L]
Currently, if I enter http://example.com/controller/function
in the browser, I receive a 404 error, but entering http://example.com/index.php?path=controller/function
works.
Thanks!
Upvotes: 0
Views: 2759
Reputation: 11809
You may try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule ^([^/]+)(.*)?$ index.php?path=$1$2 [L]
It maps internally
http://example.com/var1/var2
To:
http://example.com/index.php?path=var1/var2
Keeps the incoming trailing slash behavior and var2
is optional.
Upvotes: 6