homepage Welcome to WebmasterWorld Guest from 54.211.7.174
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Redirecting index.html to /
Can't make it work in subdirectories
thord




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

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?)

 

jdMorgan




msg:3211410
 6:17 pm on Jan 7, 2007 (gmt 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.

Jim

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved