Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Redirecting index.html to /

Can't make it work in subdirectories

12:11 pm on Jan 7, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 7, 2007
votes: 1

Having first studied documentation and several older threads here I combined the information into the following lines:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/  
RewriteRule ^(.*)index\.html$ [%{HTTP_HOST}...] [R=301,L]

but, sadly, I can only make this work in the root directory. To the subdirectories' index files the code does nothing at all. Any help?

(I am using that HTTP_HOST because there are two domains controlled by my .htaccess. Maybe this piece of code simply will not work in such a set up?)

6:17 pm on Jan 7, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

You just need to allow for zero or more directory paths in both the RewriteCond and RewriteRule, otherwise, they won't match subdirectory index requests:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://%{HTTP_HOST}/$1 [R=301,L]

I have used "([^/]+/)*" as the pattern, which means, "Match one or more characters not equal to a slash, followed by a slash, and and many instances of that sequence as you like (zero or more subdirectory levels)." Unlike using ".*", this pattern can be processed from left to right in a single pass of the pattern-matcher, and is therefore more efficient.

Try to avoid the use of the ".*" pattern. It is "easy" to use, but can be grossly inefficient, especially when it occurs more than once in a pattern.


[edited by: jdMorgan at 6:17 pm (utc) on Jan. 7, 2007]


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members