I use Win10, Apache2.4 and PHP7.4. I created 2 test sites inside Apache24htdocs – 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
?
2
Answers
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 ???
Ths will happen if the
ServerName
(orServerAlias
) directives do not match the requestedHost
header on the request. It will then default to the first<VirtualHost>
.I wouldn’t necessarily expect this to be case-sensitive, but you’ve defined the
ServerName
asTest.com
(capitalT
), but you are requestingtest.com
(all lowercase) – the browser automatically lowercases the hostname in the HTTP request anyway, so you can’t actually make a request forTest.com
.You should be defining the
ServerName
as all lowercase.Likewise, this should also be lowercase.
That looks like you are incorrectly linking to the
/Test.com
subdirectory, not thehttp://test.com
host?Do you have a similar default in the main server config, outside of a
<VirtualHost>
container?