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

msg:4055833 | 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

msg:4056118 | 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

msg:4056348 | 12:03 am on Jan 8, 2010 (gmt 0) | There is another useful thread: [webmasterworld.com...]
|
zulu_dude

msg:4056550 | 8:37 am on Jan 8, 2010 (gmt 0) | Thanks chaps! Always thankful for ways to improve my code!
|
|
|