【问题标题】:Error document configured in .htaccess file not work properly.htaccess 文件中配置的错误文档无法正常工作
【发布时间】: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


【解决方案1】:

问题不在于 htaccess 中的代码,而在于 cPanel 的配置!我对感兴趣的域禁用 WHM PHP-FM(在此处阅读如何禁用 https://support.cpanel.net/hc/en-us/articles/360049690354-How-to-Disable-PHP-FPM),因为 cPanel 的工作人员向我解释这是错误的。 (阅读此处https://support.cpanel.net/hc/en-us/articles/360050895654-ErrorDocument-directive-not-being-honored-when-using-PHP-FPM-and-the-filename-provided-has-a-php-extension

【讨论】:

    猜你喜欢
    • 2016-04-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多