Setting Up Wildcard DNS with cPanel

4.7/5 - (14 votes)

Wildcard DNS allows a server to display and combination of subdomains for a website. For example, wildcard DNS for will allow any subdomain to resolve to this website, even if they have not been specifically created. Subdomains th

at have been created individually in cPanel will still route to their respective folders, but anything else will go to the document root of the domain the subdomains are based on. Wildcard DNS is most used for implementation of applications like WordPress MU. To set up wildcard DNS:

In the DNS zone for the parent domain, simply create an A or CNAME record for *. For example, either of these will work:

* IN A


Now on the server, edit /var/cpanel/userdata/$user/$parentdomain, and look for the serveralias line. This is where the parked domains/aliases for a domain are listed, so you just need to append *.parentdomain to the same line. A serveraliase line for may look like this:

serveralias: *

Now run:


And restart Apache. You can test the Wildcard subdomains by going to any subdomain of the parent domain, and it should go to the parent domain’s site. This may not be what you wanted it to do though. With wildcard DNS and virtualhosts, you need an .htaccess rewrite to redirect the subdomains. For example:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+) [NC]
RewriteRule (.*) %2/$1 [L]

In the above example, if your subdomain is, the rewrite will send you to You can modify the rewrite accordingly to achieve the results you want.

Keep in mind that the Apache configuration has to be done by someone with access to the user’s Apache config files, as you can’t add * to cPanel as a subdomain or parked domain at this time. cPanel may change this in the future, but for now it’s something that the end user cannot do without administrator access.


  1. Pingback: Wildcard Dns Hostgator – Cyber Sun

Leave a Reply

Your email address will not be published. Required fields are marked *

Log in