Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Ensuring only one point of access for your site

Preventing duplicate content on cPanel servers



10:36 am on Jan 7, 2010 (gmt 0)

10+ Year Member

Something that I've noticed about almost all shared hosting accounts running on cPanel is that 'addon domains' can be accessed by three different methods:

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!


7:35 pm on Jan 7, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

The code has a potentially-dangerous flaw, in that if a true HTTP/1.0 request is received, it will not have an HTTP "Host:" request header. In this case, the %{HTTP_HOST} variable will be blank, and an 'infinite' redirection loop will result. This is not a problem on name-based shared virtual hosting which by definition cannot receive true HTTP/1.0 requests, but it can be a problem if the site is hosted on (or upgraded to) IP-based hosting -- e.g. if the server has a unique/non-shared IP address.

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]

Note that I use the term 'true HTTP/1.0 requests' to distinguish them from the 'extended HTTP/1.0 requests' commonly used by search engines and network proxies for backward-compatibility purposes; These extended HTTP/1.0 requests *do* have an HTTP "Host" request header and so do not cause the looping problem described above.



12:03 am on Jan 8, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

There is another useful thread: [webmasterworld.com...]


8:37 am on Jan 8, 2010 (gmt 0)

10+ Year Member

Thanks chaps! Always thankful for ways to improve my code!

Featured Threads

Hot Threads This Week

Hot Threads This Month