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

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

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?


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: https://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] 
  • 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/.

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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