Msg#: 4503261 posted 2:59 am on Oct 3, 2012 (gmt 0)
Glad to hear that. Now maybe you can do me a favour. Seeing as you are in the site from hell can you look around for any ancient texts that might be of use to us up here. Apparently the secrets of heaven are hidden in the pits of hell. Kinda cool when you think of it, who would ever want to go there looking for them.
Msg#: 4503261 posted 6:26 am on Oct 3, 2012 (gmt 0)
Your code now redirects requests for example.com/index.html to example.com/ and requests for www.example.com/index.html to www.example.com/
If you also have a non-www to www rule in your htaccess file, a request for example.com/index.html is redirected twice before eventually reaching www.example.com/ - use the Live HTTP Headers extension for Firefox to confirm this.
This unwanted redirection chain will cause issues.
You should add the canonical protocol and hostname to the rule above and make sure that the index redirect is listed before the non-www/www redirect in the htaccess file.
You should also escape all literal periods in patterns.
If your site actually uses an index.html or index.htm file to serve content you probably can't view the content now and get an error message instead. You will need to add a preceding RewriteCond looking at THE_REQUEST to ensure that only external requests for the index file are redirected, not requests for the index file that happen as a result of the final internal rewrite to fetch the content.
Finally, why redirect only root requests? Using ^(([^/]+/)*)index\.html?$ will enable this redirect for all folder levels.
Example code for this appears in thousands of previous threads. Note: If there is a (.*) pattern in the index rule then it is the wrong code.
Msg#: 4503261 posted 1:25 pm on Oct 3, 2012 (gmt 0)
Ya, what g1smd said.
I should have known my suggestion was too easy to be as efficient as the one pointed out above. But, I want to learn this stuff too so it becomes second nature so I want to participate in these types of posts. It will reinforce my understanding until I can speak regex confidently. Right now I only deal with it a couple times a year and it's usually a painful chore.
Msg#: 4503261 posted 6:07 pm on Oct 3, 2012 (gmt 0)
Besides what I said above I also tend to just hyper-focus on the exact problem presented and assume the OP is already aware and/or has other concerns taken care of -- at least here in Apache because my knowledge is limited. That's the opposite to other threads where I can easily wonder off topic expanding on the OP because my monkey-mind just likes to go wandering at times -- like right now for instance :P
Msg#: 4503261 posted 6:26 pm on Oct 3, 2012 (gmt 0)
Most htaccess files will have three groups of code: - rules that block access - rules that redirect - rules that internally rewrite.
You need a RewriteCond + RewriteRule pair to deal with index requests then a separate pair to deal with non-www/www requests. Both RewriteRules should have the canonical hostname in the rule target. This avoids the double redirect.
Generally you should order rules from most specific to most general within each of the three groups, then only one rule will match a request. The [L] flag stops the rest of the rules being tested after one has already matched.