Forum Moderators: phranque
Redirect /index.htm http://www.example.com/
I have old index.htm file on it so I need this redirect. Any other thing to work around with this? Thanks
[edited by: jdMorgan at 6:11 pm (utc) on Aug. 23, 2009]
[edit reason] example.com [/edit]
After several times through this loop, either the server or the browser 'gives up,' and in this case, the server is giving up and just serving the last-requested URL. If the browser had given up first, it would have shown you an error message.
If you examine the transactions between your browser and your server using a tool such as the "Live HTTP Headers" add-on for Firefox/Mozilla browsers, this redirection loop will be quite obvious.
You will also likely find an entry in your server error log file telling you that there is a redirection loop happening.
The 'cure' for this problem is to change your rule so that it only redirects if "index.htm" is directly-requested by the client (browser or robot), and not when it is internally requested due to the action of DirectoryIndex. Unfortunately, mod_alias cannot support this conditional redirection, so it is necessary to use mod_rewrite:
Options +FollowSymLinks -MultiViews
RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.htm
RewriteRule ^(([^/]+/)*)index\.htm$ http://www.example.com/$1 [R=301,L]
If you are already using mod_rewrite, you won't need to repeat the "Options" and "RewriteEngine on" directives; They're only needed once at the top of your mod_rewrite code.
Jim
What if I only want the index.htm on the root to be redirected to my homepage which is "http://www.example.com"? Will this mod_rewrite works without any harm on my website in relation to architecture, seo etc...?
Here's the scenario, my old site was in .htm format so I have this index.htm.
Lately I changed it to CMS using wordpress. I removed the index.htm on the root of my directory. Now, I found out that there are still request for this:
http://www.example.com/index.htm
With this current htaccess settings, it brings me to a 404 page when I try to access http://www.example.com/index.htm
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^index\.htm$ "http\:\/\/www\.example\.com" [R=301,L]
<Files 403.shtml>
order allow,deny
allow from all
</Files>
[edited by: jdMorgan at 6:10 pm (utc) on Aug. 23, 2009]
[edit reason] example.com [/edit]