错误文档(404)无效

时间:2013-09-05 21:30:06

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

以下是我的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

2 个答案:

答案 0 :(得分:0)

在.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中启用了重写模块。

答案 1 :(得分:0)

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

相关问题