localhost
will always redirect to 127.0.0.1
. You can trick this by naming your other VirtualHost to other local loop-back address, such as 127.0.0.2
. Make sure you also change the corresponding hosts
file to implement this.
For example, my httpd-vhosts.conf
looks like this:
<VirtualHost 127.0.0.2:80>
DocumentRoot "D:/6. App Data/XAMPP Shared/htdocs/intranet"
ServerName intranet.dev
ServerAlias www.intranet.dev
ErrorLog "logs/intranet.dev-error.log"
CustomLog "logs/intranet.dec-access.log" combined
<Directory "D:/6. App Data/XAMPP Shared/htdocs/intranet">
Options Indexes FollowSymLinks ExecCGI Includes
Order allow,deny
Allow from all
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
(Notice that in <VirtualHost>
section I typed 127.0.0.2:80
. It means that this block of VirtualHost will only affects requests to IP address 127.0.0.2
port 80
, which is the default port for HTTP.
To route the name intranet.dev
properly, my hosts
entry line is like this:
127.0.0.2 intranet.dev
This way, it will prevent you from creating another VirtualHost block for localhost
, which is unnecessary.