Forum Moderators: phranque

Message Too Old, No Replies

Handling requests for non-existent subdomains - with a 404?

Requests for pages on non-existent subdomain returns content found at www.

         

flashbanger

6:11 pm on Feb 5, 2007 (gmt 0)

10+ Year Member



I am a project manager for a medium sized website with several thousand pages. We spend a fair amount of time scratching our heads and wondering why we can't maintain a respectable position on Google's search results. Amongst the various possible problems we've identified, each of which we're trying to solve, we've discovered that when we prefix our domain name with a non-existent subdomain, the page resolves as if we'd requested a page from www. For example, abcd.example.com correctly delivers the content found at www.example.com.

Firstly, can anyone think of any reasons why this might affect our SERPs? We were wondering whether we risk being penalised by Google for duplicate content if Googlebots found links to incorrect subdomains on our website.

Secondly, does anyone know of an .htaccess hack which will return a 404 page to a user who tries to request a page from a non-existent subdomain?

Many thanks

Chris

[edited by: engine at 6:23 pm (utc) on Feb. 5, 2007]
[edit reason] examplified [/edit]

jdMorgan

8:02 pm on Feb 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Chris,

Welcome to WebmasterWorld!

You never know whether a link to a 'bad' subdomain is a malicious ploy by a competitor to cause duplicate-content problems for you, or simply a typo -- either on a link from a site that might be worth having, or as a result of a direct browser address bar type-in error. In all but the first case, a 404 is a 'sudden shock' to the user and therefore, inappropriate.

The simplest and safest solution is to issue a 301-Moved Permanently redirect from the incorrect (sub)domain to the requested page on the correct domain. This, along with www- vs. non-www canonicalization can be accomplished using a single rule in mod_rewrite. An example for use in httpd.conf is:


# If not canonical domain
RewriteCond %{HTTP_HOST} !^www\.example\.com
# Redirect to requested page in canonical domain
RewriteRule ^/(.*)$ http://www.example.com/$1 [R=301,L]

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim