Forum Moderators: phranque
# Index Redirect for /folder/index.html and /folder/index.php to /folder/ (or to / for root)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?|php)(\?[^\ ]*)?\ HTTP/ [NC]
RewriteRule ^(([^/]*/)*)index\.(html?|php)$ http://www.example.com/$1 [R=301,NC,L]
#
# Redirect non-canonical non-blank hostname to www
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L] # Index Redirect for /folder/index.html and /folder/index.php
# [b]and for /folder/MainMenu.html (and /folder/MainMenu.htm and /folder/MainMenu.php too)[/b]
# to /folder/ (or to / for root)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*[b]([/b]index[b]|mainmenu)[/b]\.(html?|php)(\?[^\ ]*)?\ HTTP/ [NC]
RewriteRule ^(([^/]*/)*)[b]([/b]index[b]|mainmenu)[/b]\.(html?|php)$ http://www.example.com/$1 [R=301,NC,L]
#
# Redirect non-canonical non-blank hostname to www
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L] [edited by: g1smd at 11:25 am (utc) on Mar 9, 2010]
{3,9} part matches between 3 and 9 characters, literally the GET part of the THE_REQUEST. (\?[^\ ]*)?\ part because you do want to redirect all requests for the filename. It would be an error if a stray parameter on the end of the URL meant the request failed to be redirected. The redirect should strip the parameter; add a question mark to the end of the target URL to strip any parameters. $1/Libraries/$2 should be [b]/[/b]$1/Libraries/$2 to prevent path injection from a malicious request. DirectoryIndex index.php set), but the name of the file should not appear in the URL.