1

I use Win10, Apache2.4 and PHP7.4. I created 2 test sites inside Apache24\htdocs - Test.com and Test2.com, both containing simple index.php files. Here are exceptions from config files:

hosts:

    127.0.0.1 Test.com  www.Test.com
    127.0.0.1 Test2.com www.Test2.com

httpd.conf:

    # PHP7 module
    PHPIniDir "C:/Dev/PHP-7.4.24"
    LoadModule php7_module "C:/Dev/PHP-7.4.24/php7apache2_4.dll"
    AddType application/x-httpd-php .php

httpd-vhosts.conf:

    <VirtualHost _default_:80>
        DocumentRoot "${SRVROOT}/htdocs"
        ServerName www.example.com:80
    </VirtualHost>

    <VirtualHost *:80>
        DocumentRoot "${SRVROOT}/htdocs/Test.com"
        ServerName Test.com
        ServerAlias www.Test.com
    </VirtualHost>

    <VirtualHost *:80>
        DocumentRoot "${SRVROOT}/htdocs/Test2.com"
        ServerName Test2.com
        ServerAlias www.Test2.com
    </VirtualHost>

When loading both test.com and test2.com, browser shows folder index of htdocs. Only clicking on either index shows actual site, and browser address field become, for example, http://test.com/Test.com/. How to configure apache to show site from address like test.com?

qloq
  • 689
  • 1
  • 5
  • 15

2 Answers2

0
<VirtualHost *:80>

</VirtualHost

hey apache if you get any request on port 80 go to folder test.com

hey apache if you get any request on port 80 go to folder test2.com

doh !

so if i make a localhost request http://127.0.0.1:80 apache should just magically know which folder to go to right ???

mister_cool_beans
  • 1,441
  • 1
  • 8
  • 19
  • The OP is using name-based virtualhosts (with a `ServerName` directive) and requesting the hostname, not the IP address. So it's not just "any request on port 80", it's "any request on port 80 where the `Host` header matches the value of the `ServerName` directive". – MrWhite Oct 16 '21 at 18:25
  • the ServerName directive is not going to fire because the OP is working on localhost, so they are not requesting by domain name, hence why i say any request on port 80 – mister_cool_beans Oct 18 '21 at 05:30
0

When loading both test.com and test2.com, browser shows folder index of htdocs.

Ths will happen if the ServerName (or ServerAlias) directives do not match the requested Host header on the request. It will then default to the first <VirtualHost>.

ServerName Test.com
ServerAlias www.Test.com

I wouldn't necessarily expect this to be case-sensitive, but you've defined the ServerName as Test.com (capital T), but you are requesting test.com (all lowercase) - the browser automatically lowercases the hostname in the HTTP request anyway, so you can't actually make a request for Test.com.

You should be defining the ServerName as all lowercase.

ServerName test.com
ServerAlias www.test.com
127.0.0.1 Test.com  www.Test.com
127.0.0.1 Test2.com www.Test2.com

Likewise, this should also be lowercase.

Only clicking on either index shows actual site, and browser address field become, for example, http://test.com/Test.com/

That looks like you are incorrectly linking to the /Test.com subdirectory, not the http://test.com host?

I tried to fully comment out this block - nothing changed.

Do you have a similar default in the main server config, outside of a <VirtualHost> container?

MrWhite
  • 43,179
  • 8
  • 60
  • 84