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

dole doug
  • 275
  • 1
  • 5
  • 11
  • 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

3 Answers3

3

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

CarloBaldini
  • 583
  • 2
  • 8
  • 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
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
DerfK
  • 19,493
  • 2
  • 38
  • 54
  • 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
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
ipozgaj
  • 1,081
  • 10
  • 10