简体   繁体   English

.htaccess使用mod_rewrite的自定义错误文档

[英].htaccess custom error document using mod_rewrite

I'm having some trouble working with error documents on a hosting (GoDaddy). 我在托管(GoDaddy)上处理错误文档时遇到了一些麻烦。

Here is my htaccess content: 这是我的htaccess内容:

AddHandler x-httpd-php5-4 .php

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?route=$1 [L,QSA,NE]

ErrorDocument 404 /error/NotFound
ErrorDocument 403 /error/Forbidden

RedirectMatch ^/\+(.*)$ http://plus.google.com/[my_profile]


#Options All -Indexes
DirectoryIndex index.php
AddDefaultCharset UTF-8
DefaultLanguage es-PE

SetEnvIfNoCase User-Agent .*google.* search_robot
SetEnvIfNoCase User-Agent .*yahoo.* search_robot
SetEnvIfNoCase User-Agent .*bot.* search_robot
[...]
SetEnvIfNoCase User-Agent “(Ubuntu-feisty)$” bad_bot

Order Deny,Allow
Deny from env=bad_bot
#Deny from All
Allow from env=search_robot

<ifModule mod_gzip.c>
   [...]
</ifModule>
<FilesMatch ".(ttf|otf|eot|woff)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
  </IfModule>
</FilesMatch>
#COUNTRY_BLOCK_START 
<Limit GET HEAD POST>
order deny,allow
allow from [ip_range]
deny from all
</Limit>

With all of this, custom error pages not working. 由于所有这些,自定义错误页面无法正常工作。

Try adding .html, .php or whatever the extension is for the error files to 尝试为错误文件添加.html,.php或任何扩展名

ErrorDocument 404 /error/NotFound(.html)
ErrorDocument 403 /error/Forbidden(.html)

Or if the file extensions have been removes using the .htaccess file, the add a slash to 或者,如果已使用.htaccess文件删除了文件扩展名,请在其中添加斜杠

ErrorDocument 404 /error/NotFound/
ErrorDocument 403 /error/Forbidden/

Your routing is handling all requests that are for files that don't exist (which would trigger a 404). 您的路由正在处理所有针对不存在的文件的请求(这将触发404)。 What you need to do is in your routing script ( index.php ), look for when a route doesn't exist, then return your error document from there. 您需要做的是在路由脚本( index.php )中,查找何时不存在路由,然后从那里返回错误文档。

Because of these conditions: 由于这些条件:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

Anything that would normally fall under a 404 error would be caught and routed to your index.php script. 通常会出现404错误的所有内容都会被捕获并路由到您的index.php脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM