Henry's Web Notes

My dev notes about the web

Archive for the ‘Apache’ Category

Apache: Serving Your Website Without “www”

Tuesday, August 11th, 2009

In the early days of the web, people used to always type www in front of a domain name. I believe this became a convention to distinguish the web server from other services like the mail server. In reality, there’s no need for distinction because a typical web server responds to port 80 and the mail server responds to port 25, 110, etc. There was never a rule that requires a website to start with a www or any other prefixes. So typing just your domainname.com should be a valid website address.

These days, it is now a common practice to serve a website either with or without the www prefix. In fact, most companies prefer it without the www because it’s easier to type and remember. Not to mention, the letter “w” has the longest syllable in the alphabet. Try to say that three times before the domain name. And don’t give me that “dubdubdub” stuff :)

So, if you’re hosting your own server and/or have access to the Apache configuration file (it’s usually httpd.conf or apache2.conf) and running multiple sites, you can copy the following lines in your conf file (replace example.com with your domain name):

<VirtualHost *>
    DocumentRoot /var/www/web
    ServerName www.example.com
    ServerAlias example.com
</VirtualHost>

In addition, make sure that the A Record in your DNS setting had the example.com and www.example.com pointing to the same IP address.