.htaccess modify rules and redirect if there's .php in the url
Posted
by
Ron
on Server Fault
See other posts from Server Fault
or by Ron
Published on 2011-01-30T23:07:18Z
Indexed on
2011/01/30
23:27 UTC
Read the original article
Hit count: 251
Hello everyone.
I got the following code in my .htaccess:
Options +FollowSymlinks
RewriteBase /temp/test/
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^about/(.*)/$ $1.php [L]
RewriteRule ^(.*)/download/(.*)/(.*)/(.*)/downloadfile/$ file-download.php?product=$1&version=$2&os=$3&method=$4 [L]
RewriteRule ^(.*)/download/(.*)/(.*)/(.*)/$ download-donate.php?product=$1&version=$2&os=$3&method=$4 [L]
RewriteRule ^(.*)/download/(.*)/$ download.php?product=$1&version=$2 [L]
RewriteRule ^newsletter-confirm/(.*)/$ newsletter-confirm.php?email=$1 [L]
RewriteRule ^newsletter-remove/(.*)/$ newsletter-remove.php?email=$1 [L]
RewriteRule ^(.*)/screenshots/$ screenshots.php?product=$1 [L]
RewriteRule ^(.*)/(.*)/$ products.php?product=$1&page=$2 [L]
RewriteRule ^schedule-manager/$ products.php?product=schedule-manager&page=view [L]
RewriteRule ^visual-command-line/$ products.php?product=visual-command-line&page=view [L]
RewriteRule ^windows-hider/$ products.php?product=windows-hider&page=view [L]
RewriteRule ^(.*)/$ $1.php [L]
RewriteRule ^products/$ products.php [L]
everything work perfect. I would like to know how can I modify it so it will be less lines. I am pretty sure I can atleast remove 4-5 lines, but I dont know how. (merge the schedule-manager, visual-command-line and windows-hider, and some more).
I know that the order of the rules is important, this order works - although I have no idea why, I just played with the rules until it worked. If you think that there'll be a bug with the following order please tell me where.
Another thing - I would like to redirect for example www.myweb.com/products.php to www.myweb.com/products/ (I mean that the URL in the address bar will change).
I dont know if the redirect can go along with my rewrite rules.
Thank you.
© Server Fault or respective owner