Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

.htaccess - disallowing machine names / sub-domains

.htaccess, sub-domains, machine names



8:28 pm on Jun 23, 2003 (gmt 0)

10+ Year Member


I have a site set up at Powweb, but the morons there set everyone's DNS records up to allow "anything" - ie. the DNS CNAME record simply allows "*" ... even if you don't want it. Given that a simple request to them to change it to "www" goes unfulfilled, I thought I could probably handle it within an .htaccess file.

So, I want to allow [mydomain.com...] and [mydomain.com...] (ie. they should each go to the same place), but I want to disallow any machine names/ sub-domain names - for the present time at least.

Since the DNS record is not likely to be changed any time soon, then I figure that I should be able to get an .htaccess to allow the "www".domain.com (which is really just a sub-domain) - and any page underneath it - to do a re-write to domain.com (such that a 200 http code is issued), but do a redirect on anything else (ie. test.domain.com etc, etc). The redirect would go to the main page at domain.com, but at least a http error code (301?) would get issued such that it cannot be spidered...

So, I want [domain.com...] and [domain.com...] to work as you'd normally expect, but for any other sub-domains to get re-directed to [domain.com....]

Hope that makes sense ... any help appreciated.



9:49 pm on Jun 23, 2003 (gmt 0)

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


Welcome to WebmasterWorld [webmasterworld.com]!

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

Ref: Introduction to mod_rewrite [webmasterworld.com]



10:05 pm on Jun 24, 2003 (gmt 0)

10+ Year Member

Thanks Jim - I'll give that a whirl and let you know how I go!



10:16 pm on Jun 24, 2003 (gmt 0)

10+ Year Member


That works exactly - and I mean "exactly" - how I needed it to. I really appreciate your help!

Best wishes,


Featured Threads

Hot Threads This Week

Hot Threads This Month