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