Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.


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

When I type in www.site1.com it serves pages from /home/eamorr/site1/index.php Same for www.site2.com, www.site3.com and www.site4.com

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


site1.com -> site1.com site2.com -> site1.com site3.com -> site1.com site4.com -> site1.com

How do I configure apache to do the following:

site1.com -> site1.com site2.com -> site2.com site3.com -> site3.com site4.com -> site4.com

Here is my default config:

ServerAdmin admin@site1.com ServerName www.site1.com

    DocumentRoot /home/eamorr/sites/site1.com/www
    DirectoryIndex index.php index.html

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

            #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 www.sitex.com. 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

1 Answer 1

up vote 0 down vote accepted

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

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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