0

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

1
  • 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, 2010 at 19:49

3 Answers 3

3

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

1
  • 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, 2010 at 19:49
0

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
2
  • 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, 2010 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, 2010 at 19:57
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .