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,

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


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
  • 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.