g1smd - 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.