简体   繁体   中英

XAMPP won't load index.php when using a domain name

So, when I use localhost/website/index.php to access index.php, it works just fine, yet when I use a domain name like website.com/website/index.php and try to access index.php from another page, it doesn't redirect me there, but instead, reloads the page it was already on.

Then, when I try to access index.php via the search bar, it throws an error saying This page isn't working.

Does anyone know a fix for this?

You need to set up a vhost for Xampp

Here's an example which should be added to C:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin webmaster@website
    DocumentRoot "C:/xampp/htdocs/website"
    ServerName website.com
    ErrorLog "logs/website-error.log"
    CustomLog "logs/website-access.log" common
</VirtualHost>

<VirtualHost *:443>
    ServerAdmin webmaster@website
    DocumentRoot "C:/xampp/htdocs/website"
    ServerName website.com
    SSLEngine On
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
    <Directory "C:/xampp/htdocs/website">
    php_flag log_errors on
    php_value error_log "logs/website-error.log"  
        AllowOverride All
        Order allow,deny
        Allow from all  
    </Directory>
  
  php_flag log_errors on
  php_value error_log "logs/website-error.log"  
  
    CustomLog "logs/website-access.log" common
</VirtualHost>

You also need to configure your local hosts file to send requests for website.com to your local IP address.

Your hosts file is here: c:\Windows\System32\Drivers\etc\hosts

Add an entry: 127.0.0.1 website.com

This will allow you to access the website on your local machine.

To access the website on your local network you can either change all computer's hosts files as above, or add a DNS A record into your network switch (if it supports DNS)

A website.com 192.168.1.51 (this is your LAN IP address)

If you need the internet to access the website on Xampp you need to add an A record to your public IP address in your domain name DNS control panel. You can find your pulic IP address here: https://www.whatismyip.com/ and you will also need to allow traffic on ports 80 and 443 in through your router and firewall. If you do not have a static IP address from your internet service provider, you will need to update your domain name DNS A record each time your IP address changes - eg if you restart your router, and/or periodically)

Please note: Xampp was not designed to be accessible from the internet, it will work but it's not secure. Please read https://www.makeuseof.com/reasons-why-you-should-never-use-xampp-on-production-server/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM