Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

On my machine I'm using WAMP with virtual hosts. All I did was to add my-project.loc line into system32\drivers\etc\host file and the following code into httpd-vhost.conf from the Apache2.2.11\conf\extra folder.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot "c:/wamp/www/my-project.loc"
    ServerName my-project.loc
    ErrorLog "logs/my-project.loc-error.log"
    CustomLog "logs/my-project.loc.log" common

My question is how can i make the to work too. Can you give me the smart solution, because i assume that writing the same code but this time with ServerName isn't a good idea.


share|improve this question
DerfK is right about the hosts file, but don't bother with the rewrite, add the line that the unnamed user listed. – VxJasonxV Oct 23 '10 at 19:49
up vote 3 down vote accepted

Add the following line under the ServerName directive: ServerAlias

share|improve this answer
Formatting is everything: ServerAlias This, along with DerfK's answer for the hosts file is the two things you need to do for this to work. – VxJasonxV Oct 23 '10 at 19:49

You'll need a second <VirtualHost> block with ServerName and the same DocumentRoot

Ideally, the second block would use mod_rewrite to redirect (301) all requests to one "canonical" hostname rather than having two identical copies of your website. Example:

RewriteEngine On
RedirectMatch 301 /(.*) http://my-project.loc/$1
share|improve this answer
Also, your hosts file will need to read localhost my-project.loc Otherwise you won't be able to find – DerfK Oct 23 '10 at 18:52
The second VirtualHost block is unnecessary (see the ServerAlias directive above) but adding that line to the hosts file is a great point. – pjmorse Oct 23 '10 at 19:57

Add another line to your hosts file

And then add this line after ServerName directive in your virtual host config:

share|improve this answer

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.