Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'd like all subdomains that aren't being used for anything else to go straight to my domain.

ns1.mydomain.com.   A   198.123.44.55
ns2.mydomain.com.   A   198.123.44.66
*.mydomain.com. CNAME   mydomain.com
webdisk.blog.mydomain.com.  A   198.123.44.55

However, say I have subdomain blog.mydomain.com which I still want to behave as a normal subdomain. I would like the following to happen:

     mydomain.com -->      mydomain.com
 www.mydomain.com -->      mydomain.com
 abc.mydomain.com -->      mydomain.com
blog.mydomain.com --> blog.mydomain.com

Is this possible?

share|improve this question

2 Answers 2

If you are in a shared hosting with a single directory, you can use mod_rewrite in .htaccess to redirect all the subdomains to the root.

Adapted from: http://stackoverflow.com/questions/5966827/redirecting-multiple-domains-urls-to-one-canonical-domain.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^example\.com [NC]
RewriteCond %{HTTP_HOST} !^blog\.example\.com [NC]
RewriteRule ^/?(.*) http://example.com/$1 [L,R=301,NE] 
share|improve this answer
    
I am not familiar with Apache, but that seems to solve his problem at the server level for a shared hosting plan. However, I believe there will still need to be a DNS record to tell browsers where to navigate to. This can be accomplished by creating a Wildcard DNS record. To do this, create an A record pointing to the server with * as the subdomain. –  Paul Aug 23 '13 at 23:34

Sure it's possible. But I think it's more about configuring Apache.

Define a wildcard vHost and one for the blog - load the blog-vhost first and afterwards the wildcard one.

Maybe this link is helpful for you: http://ma.tt/2003/10/wildcard-dns-and-sub-domains/.

share|improve this answer
    
Dang, I don't have access to the config file... I'm on a shared hosting plan. –  brentonstrine Jan 25 '13 at 17:09
    
Hey, maybe you should contact your shared hosting provider if it's possible to configure such a behaviour. The Shared Hosting Provider I'm using for my private Sites offers such a configuration. –  kkugelmann Jan 25 '13 at 22:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.