【发布时间】:2019-01-11 12:41:54
【问题描述】:
我有一个奇怪的错误,我在 .htaccess 中的 ErrorDocument 404 在所有情况下都不能正常工作。
如果我访问一个不存在的页面,我只会收到消息File not found.。
如果我添加了 .html 扩展名,它会显示我创建的自定义 404 页面。
https://website.com/not-found
此链接无效,我只是收到消息File not found.
https://website.com/not-found.html
但是,访问此链接后,我看到了我的自定义 404 页面。
这是我的 .htaccess 文件
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+?)/?$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ /$1 [R=301,L]
ErrorDocument 404 /app/templates/errors/404.php
ErrorDocument 403 /app/templates/errors/403.php
# Block access to hidden files and directories.
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule "(^|/)\." - [F]
</IfModule>
基本上我剥离了扩展,仅此而已。在其他网站上,此代码运行良好,可能是托管公司的问题吗? 请注意,我无权访问 apache 配置文件。
谢谢
【问题讨论】:
标签: php apache .htaccess http-status-code-404