homepage Welcome to WebmasterWorld Guest from 54.234.141.47
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Ensuring only one point of access for your site
Preventing duplicate content on cPanel servers
zulu_dude

5+ Year Member



 
Msg#: 4055831 posted 10:36 am on Jan 7, 2010 (gmt 0)

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:
addondomain.example.com
example.com/addondomain.com
addondomain.com

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!

 

jdMorgan

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



 
Msg#: 4055831 posted 7:35 pm on Jan 7, 2010 (gmt 0)

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.

Jim

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4055831 posted 12:03 am on Jan 8, 2010 (gmt 0)

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

zulu_dude

5+ Year Member



 
Msg#: 4055831 posted 8:37 am on Jan 8, 2010 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved