Forum Moderators: phranque
Clearly we only really want visitors to be able to use the third method. At best the other two methods are potentially confusing for visitors, at worst they could present serious duplicate content issues in the search engines.
So I'm using a small bit of code in my .htaccess files inside the addon domain directories to ensure visitors are only accessing my sites from the correct domain name:
#Prevent access from any other domain
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
If you're running a site on cPanel, I hope you find this useful!
Also, this code does not force canonicalization if the request includes an FQDN-format hostname and/or has a port number appended, e.g. "example.com:80", "example.com.", or "example.com.:80"
So a more-robust version of this code is:
# Externally redirect to canonical hostname if requested hostname is non-blank and non-canonical
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Jim