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 / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

.htaccess - disallowing machine names / sub-domains
.htaccess, sub-domains, machine names

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


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)


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)

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



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


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

Best wishes,

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
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