Forum Moderators: phranque
I have one page on our website that is inevitably being rewritten
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ [mysite.com...] [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.htm\ HTTP/
RewriteRule ^(.*)index\.htm$ [mysite.com...] [R=301,L]
The issue is that I have pages such as this:
mysite.com/bookindex.html
The code is causing those to not show anymore. I can see that the issue is that the condition asks for anything then index.html, so naturally this page would fit the condition. I tried directly using an absolute url as the condition, but that threw errors as well.
What happens is that the code then strips the index.html off of the url and I am left with mysite.com/book, which obviously returns 404.
Any help is appreciated.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html?$ http://www.example.com/$1 [R=301,L]
Because we are not using a back-reference to the RewriteCond pattern, only one level of parentheses is needed there, as opposed to the RewriteRule, where two levels are needed to capture the entire leading directory path (if present) for use in the substitution URL.
Jim