简体   繁体   English

使用域名时 XAMPP 不会加载索引。php

[英]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. 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 ,它不会将我重定向到那里,而是重新加载它已经在的页面。

Then, when I try to access index.php via the search bar, it throws an error saying This page isn't working.然后,当我尝试通过搜索栏访问 index.php 时,它会抛出一个错误,提示This page isn't working.

Does anyone know a fix for this?有谁知道解决这个问题?

You need to set up a vhost for Xampp您需要为 Xampp 设置一个虚拟主机

Here's an example which should be added to C:\xampp\apache\conf\extra\httpd-vhosts.conf这是一个应该添加到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.您还需要配置本地主机文件以将 website.com 请求发送到本地 IP 地址。

Your hosts file is here: c:\Windows\System32\Drivers\etc\hosts您的主机文件在这里: c:\Windows\System32\Drivers\etc\hosts

Add an entry: 127.0.0.1 website.com添加条目: 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)要访问本地网络上的网站,您可以如上所述更改所有计算机的主机文件,或将 DNS A 记录添加到您的网络交换机(如果它支持 DNS)

A website.com 192.168.1.51 (this is your LAN IP address) A website.com 192.168.1.51 (这是你的局域网IP地址)

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.如果您需要通过互联网访问 Xampp 上的网站,您需要在您的域名 DNS 控制面板中的公共 IP 地址中添加一条 A 记录。 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.您可以在此处找到您的公共 IP 地址: https://www.whatismyip.com/您还需要允许端口 80 和 443 上的流量通过路由器和防火墙。 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) 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.请注意:Xampp 并非设计为可从 Internet 访问,它可以工作,但不安全。 Please read https://www.makeuseof.com/reasons-why-you-should-never-use-xampp-on-production-server/请阅读https://www.makeuseof.com/reasons-why-you-should-never-use-xampp-on-production-server/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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