Setting Up Wildcard DNS For Subdomains

Written by Joe on May 29, 2007 – 11:32 am -

Recently I setup a free blog host using Wordpress Mu and free forum host using CyberAlien’s Script. Perhaps the most important (for both usability and search engine benefits) features is subdomain support. You don’t want your users to be stuck with a url like www.example.com/forums/?mforum=user do you? In addition to simply being ‘prettier’, there are other reasons as to why you’d want something like user.example.com instead.

As a user, I’d want a domain that’s easy to remember. Short, sweet, and to the point. As an SEO, I’d want a subdomain for other - very important - reasons. It’s common knowledge that search engines view subdomains as entirely different domain, and it’s also a fact that - Google in particular - takes into account the content on the entire domain when determining how to rank just a specific page. This is one of the reasons larger sites rank better (we’ll look at the long end of that for some other time). Having all blogs / forums hosted on the same subdomain (www) will dilute the value of all hosted sites. There are also cookie issues, among other things to worry about when you take that route.

Now that you know the importance of using subdomains for mini-sites, let’s get down and dirty. This tutorial will be for apache only - using WHM and Putty. While I’m sure you can do this with a windows server, I don’t know how (nor do I care to learn). This is pretty straight foward, though I should advise that you could cripple your web server if you botch this up - it’s a good idea to keep backups or even ask your host for help. You’ll probably need a VPS account or dedicated server, because you’ll need root and SSH access - something a reseller account or hosted account won’t have. Did I mention you should backup before altering any files? Let’s begin…

First, let’s login to WHM. On the left side navigation - under DNS functions - click “Edit DNS Zone”. Choose your zone to edit (your domain) and scrool down to where it says “Add New Entries Below this Line”. In the first box enter * (this will be your wildcard). Next box should be 14400 and A (already filled out), then in the next box input your site’s IP address. That’s all you need, click “Save” at the bottom and bind will restart. Easy right?

Now we’ll use Putty to SSH to your box and edit the httpd.conf file. If you don’t have Putty, you can download it here. Once downloaded, run the .exe file and enter your domain (or IP) and you’ll get a command prompt asking for login. Use your root login and password. Type cd /etc/httpd/conf/ (in bold) and press enter. Your now in the folder containing httpd.conf. Let’s use Pico to view / edit it, thus type pico httpd.conf and press enter. You’re now looking at the httpd.conf file.

I’d recommend doing a where is search, so press ctrl w and search for ServerAlias yourdomain.com obviously using your own domain name here. This file contains all the domains hosted on the server by the way, so make sure you go to the right one. You should find something like this (though it may not be exact):

ServerAlias yourdomain.com
ServerAdmin webmaster@yourdomain.com
DocumentRoot /home/yourdoma/public_html
BytesLog domlogs/yourdomain.com-bytes_log
ServerName www.yourdomain.com
User yourdomain
Group yourdomain
CustomLog /usr/local/apache/domlogs/yourdomain.com combined
ScriptAlias /cgi-bin/ /home/yourdomain/public_html/cgi-bin/

On the line: ServerAlias yourdomain.com you’ll need to change this to ServerAlias: *.yourdomain.com yourdomain.com. That’s the only change needed. From there, press ctrl x to close, make sure you save the changes. Before you exit out of Putty, be sure to restart httpd.conf by typing service httpd restart and pressing enter. Now you can close out of everything. You’ve now got a wildcard enabled server.


Posted in Web Development |

3 Comments to “Setting Up Wildcard DNS For Subdomains”

  1. andri Says:

    A not suceedd for my setting, do you have any idea..?

  2. Joe Says:

    What problems are you having andri? Details would be needed to help.

  3. Alex Says:

    Thanks man. It was a helpful advice. although I use MT and lighttpd.

Leave a Comment

RSS


Warning: file() [function.file]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/joehayes/public_html/wp-content/themes/xplosive/sidebar1.php(29) : eval()'d code(1) : eval()'d code on line 6

Warning: file(http://www.seobilgi.com/randomfeed.php) [function.file]: failed to open stream: Permission denied in /home/joehayes/public_html/wp-content/themes/xplosive/sidebar1.php(29) : eval()'d code(1) : eval()'d code on line 6


Warning: Invalid argument supplied for foreach() in /home/joehayes/public_html/wp-content/themes/xplosive/sidebar1.php(29) : eval()'d code(1) : eval()'d code on line 10


Warning: file() [function.file]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/joehayes/public_html/wp-content/themes/xplosive/sidebar2.php(24) : eval()'d code(1) : eval()'d code on line 6

Warning: file(http://www.seobilgi.com/feed.txt) [function.file]: failed to open stream: Permission denied in /home/joehayes/public_html/wp-content/themes/xplosive/sidebar2.php(24) : eval()'d code(1) : eval()'d code on line 6


Warning: Invalid argument supplied for foreach() in /home/joehayes/public_html/wp-content/themes/xplosive/sidebar2.php(24) : eval()'d code(1) : eval()'d code on line 10