I have a site where I am trying to change the urls using mod_rewrite from:
/directory/filename.php to directory/filename/
/directory/filename.php?id=7 to directory/filename/7/
/directory/filename.php?id=7&file_id=1 to directory/filename/7/1/
I am not able to work out the regular expressions to use for these pages though. Here is the entire .htaccess file:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^(.*)/?$ /directory/$1 [L] #Rewrite a page without $_GET variables
RewriteRule ^([^/]+)/([0-9]+)/?$ /directory/$1?id=$2 [L] #Rewrite a page with 1 $_GET variables
RewriteRule ^([^/]+)/([0-9]+)/([0-9]+)/?$ /directory/$1?id=$2&file_id=$3 [L] #Rewrite a page with 2 $_GET variables
If the
.htaccessis in thedirectoryfolder then thedirectory/path prefix will be stripped for you and you do not need to bother about it in the rewrite rules.You could use something like: