网站index.php在编辑到.htaccess后不显示

时间:2018-03-18 21:17:49

标签: php .htaccess

我对.htaccess进行了以下编辑,以隐藏文件结尾。

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\.php
RewriteRule ^ /%1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

自从进行此编辑后,每当我转到顶部主页时,例如我得到以下错误 -

The requested URL /.php was not found on this server.

虽然这适用于我的子页面,例如example.com/about.php成为example.com/about

1 个答案:

答案 0 :(得分:0)

您要查找的用于删除网址中.php扩展名的代码是:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]