Forum Moderators: phranque
I wrote following codes in my .htaccess file but couldn't fix all of them; with the following code i have fixed 1st & 3rd problem, but 2nd point is still there. Please tell me how it can be written more properly to fix all of them in once.
.htaccess file have:
---------------------
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.html$ / [R=301,L]
RewriteCond %{THE_REQUEST} ^GET\ /.*/index\.(php¦html)\ HTTP
RewriteRule (.*)index\.(php¦html)$ /$1 [R=301,L]
--------------------------------------------------------------
Looking forward for the correct code!
Rule #2 will only work if some other script defines the "REDIRECT_STATUS" variable; It is not an Apache-native variable. I believe this is a variable defined by Drupal (or something like that).
I'd suggest deleting your rule #2, modifying rule #3 to work properly with or without subdirectory paths prepended to index.html or index.php, and then reversing the rule order so that index page requests to the "wrong domain" don't result in a double redirect:
RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^(GET¦HEAD)\ /([^/]+/)*index\.(php¦html)\ HTTP
RewriteRule ^(([^/]+/)*)index\.(php¦html)$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
See also the notes on the use of the ".*" pattern in this recent thread [webmasterworld.com].
Replace all broken pipe "¦" characters in the code above with solid pipes before use; Posting on this forum modifies the pipe characters.
Jim