In some cases, you will want a subdomain to be the same as the homepage of a website. For example:
http://www.domain.com
http://sub.domain.com
http://whatever.domain.com
http://something.domain.com
http://anything.domain.com
will all show the same page. Even if you just invented one subdomain up, it will still show the same page, the homepage. Err, hmmm what’s the use of that? Well for some this is totally non-sense, but for some, it totally makes sense why to do this, where you can be having the same file running and just using server-side scripts to change content of a website dynamically. Now if you believe wildcard DNS is something you need to do in order to achieve something like this and is running a CPanel server, how can this be done?
First is, if you just have a shared hosting account and has no access to WHM and no SSH access to the httpd.conf file, you might need to ask permission from the server owner. If you run your own server, or is given the freedom to play around with these files, you can go ahead and follow the procedure.
But I do believe there may also be some other way to do this, maybe with just playing around with the .htaccess file, but tough regex commands and .htaccess modifications are not my cup of tea. Another thing is, I am not guaranteeing anyone that what you will do will not mess up your servers. Although this procedure has served me well, if ever something happens to your server as a result of following this procedure, I, the author, this website, my business, my friends, my cats and my dogs will not be held responsible for what ever losses may occur on your end.
Ok now, how to do it?
- Login to WHM
- Click on Edit DNS Zone on the side navigation.
- Choose the domain to edit, and click on the Edit button.
- Under Add New Entries Below this Line add this:
Domain: *
TTL: 14400 (this is the default value)
Record Type: A in (your IP address) - Submit and this will now be added.
- Access your httpd.conf file. Login as root, via SSH.
- To access the file in a CPanel server go to:
# cd /etc/httpd/conf/ - Use your favorite text editor, or just simply type:
# pico httpd.conf - Do a find on your domain and you may find something like this:
ServerAlias yourdomainserver.com
ServerAdmin webmaster@yourdomainserver.com
DocumentRoot /home/yourdoma/public_html
BytesLog domlogs/yourdomainserver.com-bytes_log
ServerName www.yourdomainserver.com
User yourdoma
Group yourdoma
CustomLog /usr/local/apache/domlogs/yourdomainserver.com combined
ScriptAlias /cgi-bin/ /home/yourdoma/public_html/cgi-bin/
On the line:
ServerAlias yourdomainserver.com
Change to:
ServerAlias: *.yourdomainserver.com yourdomainserver.com
- Exit or press Ctrl X if using Pico.
- Save the file when asked and replace the existing file.
- Restart the apache web server by typing in:
# service httpd restart
Done! You are all set to go. Wildcard DNS Enabled on a CPanel Server
Popularity: 7% [?]

April 18th, 2006 at 3:41 am
Wow, your text size is super small (using IE 6.0) – I’m sure there is some great info here, but I cant read it!
May 14th, 2006 at 9:08 pm
Hi, Good stuff, just what i was looking for. Help me alot… although the last command
# service httpd restart
did not work for me, i just restarted HTTP(Apache) server using WHM
May 16th, 2006 at 6:50 pm
Great concept, I just need to get it to work. Dont have shell access. When I install the file i get a line 1175 action not recognized error.
May 17th, 2006 at 5:22 am
Nice, tutorial, thanks usman for the tip.
httpd restart doesnt work on my system either.. im on freeBSD… you?
May 17th, 2006 at 9:08 am
Hi Dallas… I think you need SSH, if your host does not allow this, maybe you can find a way using the .htaccess file. But I have not tested anything. Obviously you are into SEO and I guess you will agree by experience that:
http://keywords.domain.com works better than http://www.domain.com/keywords/
And having this setup helps a lot in SEO since SEs treat each subdomain as a new website, solves some sandboxing issues and interlinking of pages helps in PR a lot.
May 17th, 2006 at 9:11 am
# service httpd restart – I believe is a Redhat thing. But if you know the syntax on how to start and start or restart any service, you can use what ever syntax is supposed to have.
I guess if that does not work, you can use WHM’s restart services. Thanks Usman for the tip to others.
May 20th, 2006 at 1:12 am
Hi Pilkster, I saw your comment on Greg’s blog and I am happy this post helped you in the subdomain plugin for wordpress. And as for the font, it is not longer as small as it was. Thanks for informing me also, so I made it bigger already.
June 18th, 2006 at 6:40 am
Well I got it to work for one site. I can take care of the settings via WHM. My provider had to do it for the Apache piece. The crazy thing is we cant get it to work on a second domain of mine with the same ISP. But it works like a charm with the SEs and a blog program. THanks!
June 18th, 2006 at 8:27 pm
Nice to know you got it working. I think you have also been to Greg’s blog. Hehe.
August 14th, 2006 at 6:40 am
If service httpd restart doesn’t work use the following command…
/etc/rc.d/init.d/httpd restart
August 14th, 2006 at 3:42 pm
Thanks Simon!
November 11th, 2006 at 12:39 pm
Now for the tough challenge. Can CPanel be configured to do this by default when a domain is parked?
November 11th, 2006 at 4:31 pm
Hi RRRRyan, it can be done. But I believe it cannot be done by default when a domain is parked. You might need to do the same httpd.conf edits. Try it out and tell us how it goes.
June 17th, 2007 at 3:08 am
Hi
I cannot get access to the “httpd.conf” on my server.
I have checked with other hosting companies, including Dreamhost and MediaTemple – neither allow access to the file.
Dreamhost and my current host recommended I attempt to enable wildcard DNS through the .htaccess file, if anyone knows how to do this, do they have an example or idea how that would work?
Alan.
December 22nd, 2007 at 9:06 am
Thanks for the information.
I followed your instructions and seems to work. But im having email problems now, The email simply does not work anymore !
Any idea’s why the email is affected by this !?
February 15th, 2009 at 11:01 am
hello benj, I stumble on this post while looking for a way to get a dynamic subdomain. ito pala yon, then all I need is a php code that will catch all the subdomain name. maraming salamat
February 15th, 2009 at 5:36 pm
Hehehe, nice research Eli, sa akin din napunta ang sagot.
Yup just catch with a $_SERVER[HTTP_HOST].
July 16th, 2009 at 10:23 am
Thanks a lot it very helpful.
August 21st, 2009 at 4:28 pm
How can he trackback ping post thousands of trackbacks and not get penalized
August 27th, 2009 at 4:13 am
Wow graet excellent
January 20th, 2010 at 10:35 pm
Any effect on subdomains or domains I normally added ??, if wildcard DNS on CPanel is enabled.
January 20th, 2010 at 10:44 pm
Nice question Tedd. Once you enable it, if you have subdomains you really create, that subdomain will work as how you configure it. The wildcard subdomains will only apply to non-existing subdomains.
January 21st, 2010 at 12:46 am
Thank you ! Benj Arriola.. It’s clear!!!!