簡體   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 ,它不會將我重定向到那里,而是重新加載它已經在的頁面。

然后,當我嘗試通過搜索欄訪問 index.php 時,它會拋出一個錯誤,提示This page isn't working.

有誰知道解決這個問題?

您需要為 Xampp 設置一個虛擬主機

這是一個應該添加到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>

您還需要配置本地主機文件以將 website.com 請求發送到本地 IP 地址。

您的主機文件在這里: c:\Windows\System32\Drivers\etc\hosts

添加條目: 127.0.0.1 website.com

這將允許您在本地計算機上訪問該網站。

要訪問本地網絡上的網站,您可以如上所述更改所有計算機的主機文件,或將 DNS A 記錄添加到您的網絡交換機(如果它支持 DNS)

A website.com 192.168.1.51 (這是你的局域網IP地址)

如果您需要通過互聯網訪問 Xampp 上的網站,您需要在您的域名 DNS 控制面板中的公共 IP 地址中添加一條 A 記錄。 您可以在此處找到您的公共 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)

請注意:Xampp 並非設計為可從 Internet 訪問,它可以工作,但不安全。 請閱讀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