Wampserver - accessing my website from an external device redirects to localhost
I am trying to put my Wampserver website "online". When I try to access my Wampserver website from a different device, the device will redirect to localhost. For example: My computer running Wampserver has a public IP Address of xx.xxx.xx.xxx. When I type "http://xx.xxx.xx.xxx/site1/" on my phone, the phone's browser will redirect to "localhost/site1/", which (obviously) fails to connect.
Computer running Wampserver/Wampserver/PHP/Apache details:
Windows 10
Wampserver 3.2.3
phpMyAdmin 5.0.2
Adminer 4.7.7
Apache 2.4.46
PHP 7.4.9
MySQL 5.7.31
The website I want to put online is inside a folder named "site1" and this is my apache vhosts.conf: (Computer's private IP is 192.168.254.13):
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
ErrorLog "${INSTALL_DIR}/errors.log"
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
#
<VirtualHost *:80>
ServerName site1
ServerAlias 192.168.254.13
DocumentRoot "c:/wamp64/www/site1"
<Directory "c:/wamp64/www/site1/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Windows hosts file:
127.0.0.1 localhost
127.0.0.1 site1
My port is forwarded properly. If I set the localhost vhost to "Require all granted" instead of "Require local", I am able to see Wampserver's config page from my phone by typing in my computer's public IP address.
Any advice to point me in the right direction would be greatly appreciated.
When I try to access my Wampserver website from a different device, the device will redirect to localhost.
One issue here is that Apache has a "default" virtual host (the first host it loads). In this case, that is your localhost
entry. This host is returned when no other virtual hosts match a request (in your case, when accessing Apache via an IP address).
As a side note, I don't believe ServerAlias
can be used for IPs. As far as I am aware, it is for name-based virtual hosts only.