homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

subdomain problem in .htaccess
subdomain htaccess

10+ Year Member

Msg#: 524 posted 1:50 pm on Apr 16, 2003 (gmt 0)


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 :-)



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

Msg#: 524 posted 3:06 pm on Apr 16, 2003 (gmt 0)


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>

Global Options:
 top home search open messages active posts  

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
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