Forum Moderators: phranque

Message Too Old, No Replies

.htaccess hangs website

Trying to redirect /index.html requests to /

         

webman10

9:46 am on Sep 3, 2006 (gmt 0)

10+ Year Member



Hi everyone,

I am having trouble with .htaccess. when i upload it to my server and then view my site it just hangs...the code is below, any ideas folks?

Redirect 301 /index.html [mysite.com...]

Thank you in advance

wirewolf

3:17 pm on Sep 3, 2006 (gmt 0)

10+ Year Member



Your syntax is wrong. Try:

RedirectMatch permanent ^/index.html$ [mysite.com...]

You can substitute temporary for permanent if you wish to. You don't have to put 301, it's understood.

John

stapel

7:11 pm on Sep 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you wait long enough, do you eventually get an error message saying something about "exceeded number of redirects"?

Thank you.

Eliz.

jdMorgan

7:48 pm on Sep 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is likely that your index file is index.html. Therefore, mod_dir rewrites requests for "/" to "/index.html", and your code redirects it back, generating a loop.

If you have access to mod_rewrite, the problem can be fixed in your top-level .htaccess file like so:


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

This redirects requests for "/index.html" to "/", but only if the client (browser or robot) directly requested "/index.html". So it won't be invoked if "/index.html" is requested as a result of mod_dir's action. Thus, it breaks the loop described above.

If you do not have mod_rewrite permissions, then another fix is to rename index.html to something else, such as "homepage.html" and then modify or add a DirectoryIndex directive to your .htaccess file:


DirectoryIndex homepage.html

Again, this effectively breaks the "/index.html" request loop described above.

Jim

webman10

9:24 pm on Sep 3, 2006 (gmt 0)

10+ Year Member



Thanks guys for your response....JD Morgan i used your method and is redirecting fine! Thank you!

Mokita

3:27 am on Sep 4, 2006 (gmt 0)

10+ Year Member



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

Jim,

Please would you explain why it needs the "-MultiViews"? I haven't seen that used in mod_rewrite previously.

TIA.

jdMorgan

3:34 am on Sep 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Basically, in case the chosen index file name is index.htm. If that were the case, content negotiation might kick in and defeat the whole method.

Surprisingly, many shared hosts enable multiviews, and recently we've had several cases where it interfered with rewrites such as "extensionless files" and a few other things. See the mod_negotiation documentation at apache.org for more details.

Jim