Enable Wildcard Subdomains in cPanel

Wildcard subdomains can be used if you wish to redirect all visitors to your ‘main’ website regardless of what subdomain they are trying to access.

This is also useful when those who remember FIDO, Gopher and stuff mistype the www part, for example type ww.domain.com

Yet another case when you really need wildcard subdomains is using WordPress Network (previously known as WordPress Multisite or WPMU) and want users blogs to look like user.domain.com

There are 3 possible ways to enable wildcard subdomains on your website hosted at WebHostingBuzz

1. The easiest way is to create a subdomain *.yourdomain.com. Our customers can do this at cPanel > Subdomains.

[alert]Make sure that subdomain’s Document Root is public_html, otherwise this solution won’t work.[/alert]

2. If you have access to WHM – log into WHM and go to Edit DNS Zone. Select the domain you want to enable wildcard subdomains from the list.

Under Add New Entries Below this Line fill in the fields so that they look like this:

*   14400   IN   A

Be sure to replace with the actual IP of your server.

3. Yet another way to enable wildcard subdomains is to edit httpd.conf (Apache configuration) file directly. You will need SSH root access to the server in order to do this.

[alert style=danger]Don’t use this method on servers with cPanel. At some point all changes you make will be overwritten by cPanel/WHM[/alert]

Log in as root and open httpd.conf file. It is usually located in /etc/httpd/conf, but the path may differ depending on your Linux distro.

Find the VirtualHost entry for the domain name you want to enable wildcard subdomains. It’ll look like this:

ServerAlias www.domain.com
ServerAdmin [email protected]
DocumentRoot /home/domain/public_html/
ServerName domain.com
User domain
Group domain
BytesLog /usr/local/apache/domlogs/domain.com-bytes_log
CustomLog /usr/local/apache/domlogs/domain.com combined
ScriptAlias /cgi-bin/ /home/domain/public_html/cgi-bin/

The only modification you need to make is change:

ServerAlias www.domain.com


ServerAlias *.domain.com

Restart Apache when you’re done, and wildcard subdomains will work for domain.com right away.

Was this article helpful?
Spread the word!