Forum Moderators: phranque

Message Too Old, No Replies

Redirecting index.html with mod_rewrite

         

mjbnz

6:30 am on Mar 22, 2005 (gmt 0)



Hello..

I'm attempting to use mod_rewrite to redirect the root index.html to /, so that the web site author has the freedom to move between the different DirectoryIndex filenames as he chooses. (Basically this is to get around people having explicit bookmarks and links to index.html, or I wouldn't bother, and just tell him to move to index.php as he wants to)

Something like the following:

RewriteEngine On
RewriteRule ^/index.html$ / [R=permanent,NS]

But, for the life of me, I can't get this to work when index.html still exists (which is important, the choice of what to use still needs to be there). It's like the nosubreq option is being ignored - I know this isn't the case, since a debug level log is showing that it is working as expected.

Any hints/tips?

jdMorgan

12:45 am on Mar 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mjbnz,

Welcome to WebmasterWorld!

Subrequests don't affect this because you're doing an external redirect. So, you can delete the [NS] flag and I recommend you add the [L] flag, i.e. use [R=301,L].

I've run into this situation before, and the way I fixed it was to change the file "index.html" to "index.htm" and then change the DirectoryIndex directive to match. Otherwise, you just get a two-step infinite loop, since DirectoryIndex reverses what your rule does, and vice-versa.

Jim