I am configuring the .htaccess for a website.
I would like to rewrite the url from
http://www.example.com/search/foo/bar/baz/... (any number of subdirectories)
to
http://www.example.com/forms/index.php?i=foo--bar--baz--...
Another option would be to redirect all urls
http://www.example.com/search/foo/bar/baz/...
to
http://www.example.com/forms/index.php
And have index.php parse the uri.
I tried the following mod_rewrite to implement the 2nd alternative above
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule !^index\.php$ /forms/index.php but I get a 404 error.
Note: not sure if it matters, but this is happening on a Wordpress site. The whole .htaccess is
Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule !^index\.php$ /forms/index.php # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress Any help would be appreciated.
Thanks.
EDIT1:
I made some progress. I was missing [L] at the end of the RewriteRule.
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule !^index\.php$ /forms/index.php [L] Works. Now I need to check for /search in the url.
EDIT2:
More progress:
RewriteEngine On RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^search/(.*)$ http://www.example.com/forms/index.php?i=$1 [QSA,L] it seems to be working. Passing everything after search/ as parameter i.
Now I would like to still show the original url in the address bar (not the re-written one). Any way of doing that?
Thanks