Welcome to WebmasterWorld Guest from

Forum Moderators: bakedjake

Message Too Old, No Replies

subdomain problem in .htaccess

subdomain htaccess



1:50 pm on Apr 16, 2003 (gmt 0)

10+ Year Member


My expertise lay more in the programming aspect of web development, so I thought I would give this forum a try...

A year or more ago our web host was moving sites from server to server. When Google spidered our site I noticed that many of our website URLs Google linked to magically became something like:


Notice the subdomain "NEW" part of the url. This "NEW" subdomain was totally our webhosts doing for whatever reason - I assume it had soomething to do with move to the new servers and google having indexed the site while this was happening. Of couse I could be wrong.

The problem is now that the "NEW" subdomain is no longer being used but many of these links in Google still exist - and when clicked on give page not found errors that do not seem to be caught in this portion of the .htaccess file:

ErrorDocument 403 [oursitename.com...]
ErrorDocument 404 [oursitename.com...]

I was thinking of using a RedirectMatch in the .htaccess but do not know how to properly format it... Perhaps something like:

RedirectMatch (.new*)\* [oursitename.com...]

Any help would be greatly appreciated :-)


3:06 pm on Apr 16, 2003 (gmt 0)

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


ErrorDocument directives must (almost always) contain only a local path. If you use a canonical URL, the server response code will be changed to a 302 redirect - and that is NOT what you want for 403 and 404!

However, this likely has nothing to do with your problem.

If you have priveleges to use mod_rewrite, the following code added to .htacess will fix your problem:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
RewriteRule ^(.*)$ www.yourdomain.com/$1 [R=301,L]

That's it!

This says, "If the requested http_host (requested domain name) is not "www.yourdomain.com", then do an external permanent redirect to www.yourdomain.com"

More info: Introduction to mod_rewrite [webmasterworld.com]


<added>Used mod_rewrite because Redirect, RedirectPermanent, RedirectMatch, etc., cannot "see" the requested domain name, but mod_rewrite can.</added>


Featured Threads

Hot Threads This Week

Hot Threads This Month