Forum Moderators: phranque
I thought this was right, but doesn't seem to work. Site still working on non-www. Am I doing something wrong?
(This is used in a subdirectory)
^^^ redirects example.com to www.example.com
RewriteCond %{THE_REQUEST} ^.*\/index\.htm?
RewriteRule ^(.*)index\.html?$ http://www.example.com/$1 [R=301,L]
^^^^ redirects www.example.com/index.htm to www.example.com
I'd recommend reversing the rules (as you did) and using [L] on both rules, but in fact it *can* be done by omitting the [L] as shown. This approach might cause some efficiency-related problems if there were a lot of additional rules following the two shown, but if those two were the only rules, then it would work well.
mod_rewrite -- A million ways to do it, and some of them will work... Far fewer still are optimal. :)
Jim
I prefer to code this function in a non-ambiguous manner using a negative-match pattern for speed:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?
RewriteRule ^(([^/]+/)*)index\.html?$ http://www.example.com/$1 [R=301,L]
Jim
[edited by: jdMorgan at 11:54 pm (utc) on July 18, 2007]