删除.htaccess中的.php文件(如果此类文件不存在,则将用户重定向到自定义404页面)


Remove .php in files (redirect user to custom 404 page if such file does not exist) in .htaccess

我需要一个快速修复,

我已经完成了一个网站,我使用.htaccess重写url以删除.php,我的意图只有已知的文件,即,如果我有about.php,那么我可以有/about,它与以下.htaccess行工作良好

Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]

现在我创建了另一行来处理自定义404错误

ErrorDocument 404 /404.html

现在这里的问题,我得到500 Internal Server Error导航到未知的文件,而不是重定向到404....

Apache重写是某种程度上的挥舞,所以我只是没有时间,请任何帮助

感谢期待

好吧,你应该能够去页面没有。php,所以如果你有一个头文件或配置文件,只要把这段代码在会话之后的东西。您可以删除重写规则。

if (substr($_SERVER['REQUEST_URI'], -4) === '.php') {
    require '404.php';
}