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.

On my machine I'm using WAMP with virtual hosts. All I did was to add 127.0.0.1 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
</VirtualHost>

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

TY

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
add comment

3 Answers

up vote 3 down vote accepted

Add the following line under the ServerName directive: ServerAlias www.my-project.loc

share|improve this answer
    
Formatting is everything: ServerAlias www.my-project.loc 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
add comment

You'll need a second <VirtualHost> block with ServerName www.my-project.loc 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
1  
Also, your hosts file will need to read 127.0.0.1 localhost my-project.loc www.my-project.loc Otherwise you won't be able to find www.my-project.loc –  DerfK Oct 23 '10 at 18:52
1  
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 comment

Add another line to your hosts file

127.0.0.1 www.my-project.loc

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

ServerAlias www.my-project.loc
share|improve this answer
add comment

Your Answer

 
discard

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.