【问题标题】:Error document (404) not working错误文档 (404) 不起作用
【发布时间】:2013-09-09 21:00:51
【问题描述】:

以下是我的 htaccess 代码,请告知我做错了什么。谢谢你。 我正在尝试添加错误文档。 404在网站根目录下。

ErrorDocument 404 /404.html

<FilesMatch "\.(jpg|jpeg|png|gif|swf|ico|css|js)$">
    Header set Cache-Control "max-age=604800, public"
</FilesMatch>
AddDefaultCharset UTF-8
AddLanguage en-US .html .htm .css .js
#Header unset ETag
FileETag none
<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>
<IfModule mod_mime.c>
    AddType application/javascript          js
    AddType application/vnd.ms-fontobject   eot
    AddType application/x-font-ttf          ttf ttc
    AddType font/opentype                   otf
    AddType application/x-font-woff         woff
    AddType image/svg+xml                   svg svgz 
    AddEncoding gzip                        svgz
</Ifmodule>
#Gzip
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x- javascript application/javascript
AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</ifmodule>
#End Gzip

【问题讨论】:

  • 404.html 里面是什么,你怎么知道它不起作用?
  • @anubhava 它只是有点风格。当我输入虚假地址时,它会将我带到标准 404。“未找到请求的 URL /sh/showhaus_v2/about/asfdsf 在此服务器上找不到。此外,在尝试使用时遇到 404 Not Found 错误ErrorDocument 来处理请求。”
  • 好的,谢谢您的回复。 .htaccess 是否启用?
  • @anubhava 是的。其他一切都有效,只是不是 404
  • 好的,你可以试试:ErrorDocument 404 /

标签: html .htaccess http-status-code-404


【解决方案1】:

在您的 .htaccess 中使用这些代码来捕获 404 错误页面。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /404.html [L]
</IfModule>

现在您的所有 404 请求都将转到 /404.html。 您还可以使用 /404.php 进行更动态的编码。 还要确保在您的 apache 中启用了重写模块。

【讨论】:

  • 感谢您的回答。但我必须根据我的需要修改它,因为找不到文件错误我得到了。我修改后的代码:&lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . 404Page.php [L] &lt;/IfModule&gt;。无论如何,谢谢。随意浏览我的个人资料
  • 应该完全避免动态错误文档,保持它们静态。如果是服务器错误或软件错误导致错误被抛出,那么你不应该尝试做更多动态的东西。
【解决方案2】:

请使用指向 404.html 错误页面的直接链接 即。 错误文档 404 http://example.com/404.php

【讨论】:

    猜你喜欢
    • 2012-06-22
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 2013-09-19
    • 2011-02-26
    • 2010-12-29
    相关资源
    最近更新 更多