gpt4 book ai didi

php - 从硬编码HTML站点中删除index.php

转载 作者:行者123 更新时间:2023-12-02 04:21:18 26 4
gpt4 key购买 nike

我从头开始编码了一个站点,索引文件名为index.php。

该网站是实时的,但是每次访问首页时,我都会看到domain.com/index.php

我需要一个解决方案,以便每次访问主页时都只能看到domain.com,而看不到domain.com/index.php。

到目前为止,我在这里看到的解决方案仅剥离了.php部分,任何使用该解决方案的人都可以使我将主页视为domain.com,而不是domain.com/index.php应该可以帮助我。

最佳答案

如果您使用的是Apache,请在.htaccess文件中使用以下代码。如果您没有.htaccess文件,请在根目录中创建一个。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>

如果您使用的是 Nginx,请在 Nginx conf文件的顶级服务器子句中使用以下重写。
rewrite ^(.*)/index.php$ $1 permanent;

location = /index.php{
rewrite ^ / permanent;
try_files /index.php=404;
}

找不到文件时,= 404部分返回404错误。

关于php - 从硬编码HTML站点中删除index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59621278/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com