【问题标题】:ErrorDocument 404 /404.html is not working in .htaccess file in APACHEErrorDocument 404 /404.html 在 APACHE 的 .htaccess 文件中不起作用
【发布时间】:2018-01-03 09:10:14
【问题描述】:

在带有 Apache 的 Linux 服务器上的 mydomain.pe,我在 RewriteEngine on 下的 .htaccess 中添加了以下行 ErrorDocument 404 /404.html

但是,在进行错误的 url 测试时:abc.mydomain.pe/etc.html 默认会抛出 404 错误。

我的 404.html 文件可以通过网络在 url 中看到:abc.mydomain.pe/404.html

请大家多多支持,我有时间,一直没能在我身边解决。

这可能会发生吗?我分享了我的.htaccess 文件:

<IfModule mod_rewrite.c>
RewriteEngine on
ErrorDocument 404 /404.html

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ $1.html

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.abc.mydomain.pe/$1 [R,L]

RewriteCond %{HTTP_HOST} !^www.abc.mydomain.pe$ [NC]
RewriteRule ^(.*)$ https://www.abc.mydomain.pe/$1 [L,R=301]

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]
Options -Indexes
</IfModule>


<IfModule mod_headers.c>
<FilesMatch ".(js|css|xml|gz|html)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>

<IfModule mod_deflate.c>
    <filesMatch "\.(js|css|html|php)$">
        SetOutputFilter DEFLATE
    </filesMatch>
</IfModule>

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
ExpiresByType text/javascript "access 1 month"
</IfModule>
## EXPIRES CACHING ##

## INICIO compresión gzip (mod_deflate)
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/shtml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule> 
## FIN compresión gzip (mod_deflate)##

# php -- BEGIN cPanel-generated handler, do not edit
# Configure el paquete “ea-php56” como el lenguaje de programación predeterminado “PHP”.
<IfModule mime_module>
  AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

【问题讨论】:

    标签: html apache .htaccess errordocument


    【解决方案1】:

    如果您的域是 mydomain.pe,那么您的错误文档可能位于错误的位置,正如您在 abc.mydomain.pe/404.html

    中所说的那样

    也许您应该将文件 404.html 复制到 mydomain.pe/404.html,因为 Apache 会在那里寻找它。它应该可以通过 mydomain.pe/404.html 访问,而不是通过 abc.mydomain.pe/404.html

    【讨论】:

    • 感谢您的及时回复,正在使用的域是 abc.mydomain.pe(子域),但我的 mydomain.pe 中也有 404.html,这在 URL 中可见但不是在进行 URL 错误测试时加载。我也想过这个问候,Axel P.
    【解决方案2】:

    我已经能够通过 cPanel 面板使用“错误页面”修复它,有点奇怪,我注意到创建了一个 404.shtml 文件(添加了“s”),这对我来说是新的,也许 EasyApache 4 可以工作现在也是。

    感谢您的阅读, 阿克塞尔 P.

    【讨论】:

    • 我回答得太晚了几年,但我认为这取决于启用站点/*.conf(它覆盖了自定义 .htaccess):这是放置自定义的正确位置Ubuntu 发行版上的 ErrorDocument 指令(OP 未提及使用的 hte 发行版)
    猜你喜欢
    • 2014-05-23
    • 2011-12-01
    • 2013-01-04
    • 2021-10-27
    • 1970-01-01
    • 2018-03-10
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多