WWW FAQs: How can I make my website work without www. in front?

2005-08-06: as explained in Why do some web sites have www. in the name?" preceding the domain name with www. is just a popular choice. A website can have any valid fully qualified domain name. If you own the domain example.com, nothing at all prevents you from running a website called superchickens.example.com.

In practice, though, users expect two things, and if you don't provide them users will be frustrated and not find your site:

1. If your domain is example.com, then your website needs to respond when a user types just example.com in the address bar and presses Enter, because that is convenient.

2. Your website should also respond with the same content when a user types www.example.com, because the www. prefix is very common and many users will assume they must provide it.

So how do we do this? If you are paying for service from a web hosting company, and www.example.com works but example.com doesn't, then your hosting company needs to fix that for you right away. Contact technical support and let them know you will be switching hosting companies if they don't fix it promptly. There is no valid reason why they can't make both names work for you. It is a very simple change to the web server's configuration and they ought to be doing it automatically for every new customer anyway.

That's the answer for nearly everyone reading this. However, if you are running the web server yourself -- possibly because you run a web hosting company -- here are the steps you need to follow to do the job:

1. Adjust the DNS settings for example.com. Make sure you have address records (type A records) for both example.com and www.example.com, with the same IP address. This is not hard to do at all with both Windows and Linux DNS servers.

2. If you are using virtual hosting to provide many websites on a single IP address, you will also need to tell your web server about the alternative name for the site. In your web server's configuration, add example.com as an alias for www.example.com. In an Apache server httpd.conf file, this typically looks like:

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

Only the ServerAlias directive is new. the rest is shown to provide context. Your Apache VirtualHost configuration may not be identical.

After the configuration file is edited the Apache web server must be signaled to reload its configuration. On a typical Unix system this can be done with the following command:

service httpd reload

Legal Note: yes, you may use sample HTML, Javascript, PHP and other code presented above in your own projects. You may not reproduce large portions of the text of the article without our express permission.

Got a LiveJournal account? Keep up with the latest articles in this FAQ by adding our syndicated feed to your friends list!