Forum Moderators: mack
How much of a problem is this, how does it happen, and what can I do about it? Please keeping in mind that until a couple of days ago, I never heard of "canonical problems," and am not even really sure what the term means (though I did Google it, and ended up back on another wemasterworld forum, where the discussions were over my head). :-)
Many thanks for any and all enlightenment.
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.html? [NC]
RewriteRule ^(([^/]*/)*)index\.html?$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
First, this forces all index pages, both index.html and index.htm to / for both non-www and www, and forces them all to be on www. The redirect works for index pages both in the root and in any folders, and the 301 redirect preserves the folder name in the redirect.
Secondly, for all pages that are on non-www the other 301 redirect forces the domain to be www. This second directive is never used by index pages as the first directive will have already converted all of them.