【发布时间】:2021-03-27 02:52:39
【问题描述】:
在我的 cPanel 帐户中,我有一个如下所示的 htaccess 文件:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^(.*)\.html$ $1.php [nc] //for rewrite all .php file with .html extension
RewriteRule ^$ /index.html [R=301,L] //for rewrite home page to url with index.html
RewriteRule ^/$ /index.html [R=301,L] //for rewrite home page to url with index.html
ErrorDocument 404 /404.html
问题是:当我打开链接时: https://www.domainname.tld/test ---> 我有正确的 404 错误(页面不存在) https://www.domainname.tld/test.php 或 test.html ---> 我有 Apache 的默认 404 错误
这很奇怪……
我联系了 cPanel 支持,他们说我不是 cPanel 错误 你能帮帮我吗?
【问题讨论】:
-
这是因为
RewriteRule指令优先于ErrorDocument。当请求是针对file.html时,您的服务器正在读取RewriteRule ^(.*)\.html$ $1.php [nc]而不是ErrorDocument 404 /404.html。
标签: apache .htaccess http-status-code-404 cpanel