Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


I have an apache2 server with 4 domain names point to my server's single IP address.

When I type in it serves pages from /home/eamorr/site1/index.php Same for, and

However, when I type in to the address bar of a browser without the www, it always redirects to!

i.e. -> -> -> ->

How do I configure apache to do the following: -> -> -> ->

Here is my default config:

ServerAdmin ServerName

    DocumentRoot /home/eamorr/sites/
    DirectoryIndex index.php index.html

    <Directory /home/eamorr/sites/>
            Options Indexes FollowSymLinks MultiViews
            Options -Indexes
            AllowOverride all
            Order allow,deny
            allow from all
            php_value session.cookie_domain ""

            #Added by EOH for redirection
            RewriteEngine on
            RewriteRule ^([^/.]+)/?$ driver.php?uname=$1 [L]


    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

I'd like to look at the domain name and then redirect to Is there an Apache rule to do this?

I hope someone can help. My SysAdmin/apache2 config skill aren't the best.

Many thanks in advance,

share|improve this question

marked as duplicate by Wesley, Andrew Schulman, kasperd, Falcon Momot, Ladadadada Oct 7 '14 at 12:55

This question was marked as an exact duplicate of an existing question.

up vote 0 down vote accepted

You should add ServerAlias right below ServerName And so on for all your virtual hosts. Like this:

share|improve this answer
Wow! That was easy (if you know how!) Thanks so much, – Eamorr Feb 4 '11 at 23:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.