0

I made 2 virtualhosts in XAMPP Apache environment in in httpd.conf Only first one works. Second one resolves to first entry.

<VirtualHost *:80>
    DocumentRoot "C:\xampp\htdocs\shop1"
    ServerName shop1
    ServerAlias shop1
    DirectoryIndex index.php index.html index.htm not-a-file
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:\xampp\htdocs"
    ServerName localhost
    ServerAlias localhost
    DirectoryIndex index.php index.html index.htm not-a-file
</VirtualHost>

If I switch entries I get same results only other site is shown. In hosts table, I have both

127.0.0.1 localhost 127.0.0.1 shop1

Each time, I change httpd.conf, I restart apache server. Cleared browser cache each time.

1
  • The first virtual host is the fallback (default). You might want to check what your browser actually sends in the Host header field. It’s probably not just “shop1”. An easy way to check this would be your browser’s integrated debugging tool or an external program like Fiddler.
    – Daniel B
    Nov 30, 2014 at 17:01

2 Answers 2

0

You have to define the ip address of multiple vhosts will be served on with NameVirtualHost directive.

NameVirtualHost 127.0.0.1

Here is the documentation

0

This should work for you

NameVirtualHost *
    <VirtualHost *>
        DocumentRoot "C:\xampp\htdocs"
        ServerName localhost
    </VirtualHost>
    <VirtualHost *>
        DocumentRoot "C:\xampp\htdocs\shop1"
        ServerName shop1
        <Directory "C:\xampp\htdocs\shop1">
            DirectoryIndex index.php index.html index.htm not-a-file
        </Directory>
    </VirtualHost>

You must log in to answer this question.