Forum Moderators: Robert Charlton & goodroi
example.com/greenwidgets
example.com/green-widgets
www.example.com/greenwidgets
www.example.com/green-widgets (canonical) (www.)example.com/greenwidgets to www.example.com/green-widgets and another example.com/green-widgets to www.example.com/green-widgets example.com/greenwidgets to www.example.com/greenwidgets and then another to www.example.com/green-widgets and this is exactly what you must avoid.
# Externally redirect to canonicalize the domain name if a non-canonical
# hostname is requested, in order to prevent duplicate-content problems
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
#
# Externally redirect only direct client requests for /index.php
# and /index.html and /index.htm to URL ending with slash.
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html?|php)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(html?|php)$ http://www.example.com/$1 [R=301,L] example.com/index.html is requested. example.com/index.html --> www.example.com/index.html www.example.com/index.html --> www.example.com/ # Externally redirect only direct client requests for /index.php
# and /index.html and /index.htm to URL ending with slash.
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html?|php)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(html?|php)$ http://www.example.com/$1 [R=301,L]
#
# Externally redirect to canonicalize the domain name if a non-canonical
# hostname is requested, in order to prevent duplicate-content problems
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L] example.com/index.html --> www.example.com/ = Job Done! www.example.com/green-widgets/acme-widget - the final URL. example.com/greenwidget/acmewidget.html?randomjunk - for example this URL has 6 errors.