Forum Moderators: phranque

Message Too Old, No Replies

Take time to load homepage

Redirect /index.htm

         

digic

8:45 am on Aug 23, 2009 (gmt 0)

10+ Year Member



Why is it that when I have this on my htaccess the homepage takes time to load:

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]

jdMorgan

3:31 pm on Aug 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Likely because you've got "/" mapped to "index.htm" using a DirectoryIndex directive (either in your .htaccess file or in a server configuration file), so your Redirect directive interacts with the DirectoryIndex directive, creating an 'infinite' rewrite/redirect loop.

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]

This will redirect a request for www.example.com/<any number of directory levels>/index.htm to www.example.com/<any number of directory levels>/

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

digic

3:37 pm on Aug 23, 2009 (gmt 0)

10+ Year Member



Thanks jdMorgan.

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]

jdMorgan

6:13 pm on Aug 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




Options +FollowSymLinks -MultiViews
RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.htm
RewriteRule ^index\.htm$ http://www.example.com/ [R=301,L]

Note that there are no quotes or backslashes required in the substitution URL.

This rule must go before your WP rewrite rule.

Jim

digic

12:53 am on Aug 24, 2009 (gmt 0)

10+ Year Member



Thanks a lot jim

It works...