Knowledge Base
MilesWeb / Domain Name & DNS Issues

How to add a wildcard DNS record?

Approx. read time : 2 min

Wildcard DNS works in such a way, that any subdomain redirects to your primary domain.

For example, when set, anyone typing subtest.mydomain.com or subtest123.mydomain.com will be redirected to mydomain.com.

It is also used to redirect queries like ww.mydomain.com to www.mydomain.com, where ww is wrongly typed.

WildCard subdomains can be set by either of the three ways:

1. Setting it from cPanel

2. Setting it from WHM

3. Setting it from httpd.conf

1. Setting it from cPanel

a. Log into your cPanel

b. Go to Subdomains

c. Add subdomain * in the box next to the field ‘Subdomain’ of your primary domain. Make sure that the Document Root is set to public_html folder.

While adding Wildcard subdomain to your Addon domain, you just need to be sure to set the Document Root to that of the Addon Domain and not the primary domain.

2. Setting it from WHM

If you have access to WHM, then you need to

a. Go to Edit DNS Zone

b. Select the required domain

c. Under Add New Entries Below this Line insert as below

wildcarddns

 

NOTE: Please replace 20.x.xx.xx with the actual IP of the account.

3. Setting it from httpd.conf

 In order to use this method, you need root access to the server.

a. Login as root

b. Edit httpd.conf  (commonly located at /etc/httpd/conf) with your favorite text editor such as Vim or Nano and go to the VirtualHost entry of the domain/website.

<VirtualHost 20.x.xx.xxx:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /home/mydomain/public_html
ServerAdmin webmaster@mydomain.com
UseCanonicalName Off
CustomLog /usr/local/apache/domlogs/mydomain.com combined
CustomLog /usr/local/apache/domlogs/mydomain.com-bytes_log “%{%s}t %I .\n%{%s}t %O .”

c. The line ServerAlias www.mydomain.com is of your interest. Simply replace www with * which should look like ServerAlias *.mydomain.com

That’s it !

Save