问题403重定向禁404未找到 [英] Problem redirecting 403 Forbidden to 404 Not Found
问题描述
我的.htaccess的相关部分看起来是这样的:
选项-Indexes
< FilesMatch包括>
订购允许,拒绝
所有拒绝
< / FilesMatch>
RedirectMatch 404 ^ /包括(/.*)$
和它产生以下反应:
- /包括403
- /有/ 404
- /include/config.inc 403
我可以通过看我的方式告诉大家,问题很可能在(/.*)的一部分,但一切我都试过给了我同样的结果;而不是一直让404我得到一个404的一个案件和403的一切。 什么是错的,我使用了前pression?另外,因为我必须这样做了几个目录是有一揽子的办法,让我所有的403响应转换为404?
更新:我发现,通过移除FileMatch我取得更好的成绩,所以我的.htaccess,现在看起来是这样的:
选项-Indexes
RedirectMatch 404 ^ /包括(/.*)?$#加dlamblin的第一项建议
和产生以下反应:
- /包括404
- /有/ 404
- /include/config.inc 403
更新:有趣的是我发现下面产生不同的输出:
RedirectMatch 404 ^ /包括(/ |?/.*)$
RedirectMatch 404 ^ /模板(/ |?/.*)$
模板图案所有情况下的工作包括但仍然产生403中包含的所有文件(例如/include/config.inc)的难道这是一个问题的目录名,而不是与htaccess的一个问题文件本身?
更新:下面在我的.htaccess访问/include/config.inc时被相冲突与重定向
< FilesMatch配置>
订购允许,拒绝
所有拒绝
< / FilesMatch>
我可以理解为什么/ include是没有抓到你的RedirectMatch,你是不是做到底/可选的,但是/有/配置。公司的部分是一个有点令人费解的一面。
下面是我的工作在Apache 2.2:
< FilesMatch /include(/?|/.*)>
订购允许,拒绝
所有拒绝
< / FilesMatch>
RedirectMatch 404 ^ /包括(/ |?/.*)$
此处理这些情况:
/包括404
/有/ 404
/include/config.inc 404
我的/有部分正常工作,改变顺序FilesMatch部分。
编辑:
本场比赛也行不工作的< FilesMatch>在.htaccess部分,并给出了预期的效果。
The pertinent part of my .htaccess looks like this:
Options -Indexes
<FilesMatch include>
Order allow,deny
Deny from all
</FilesMatch>
RedirectMatch 404 ^/include(/.*)$
And it's generating the following responses:
- /include 403
- /include/ 404
- /include/config.inc 403
I can tell by looking at my pattern that problem is likely in the (/.*) part but everything I have tried gives me the same results; instead of consistently getting 404 I get a 404 for the one case and 403 for everything else. What is wrong with the expression I'm using? Alternatively since I have to do this for a few directories is there a blanket approach that would allow me to convert all 403 responses to 404?
UPDATE: I've found that by removing the FileMatch I get better results, so my .htaccess now looks like this:
Options -Indexes
RedirectMatch 404 ^/include(/.*)?$ # Added dlamblin's first suggestion
And generates the following responses:
- /include 404
- /include/ 404
- /include/config.inc 403
UPDATE: Interestingly enough I have discovered that the following produces different output:
RedirectMatch 404 ^/include(/?|/.*)$
RedirectMatch 404 ^/template(/?|/.*)$
The template pattern works on all cases however include is still generating 403 for all files in include (e.g. /include/config.inc) Could this be an issue with the directory name and not a problem with the .htaccess file itself?
UPDATE: The following in my .htaccess was conflicting with redirect when accessing /include/config.inc.
<FilesMatch config>
Order allow,deny
Deny from all
</FilesMatch>
I can understand why the /include isn't caught by your RedirectMatch, you aren't making the end '/' optional, however the /include/config.inc part is a bit on the puzzling side.
Here is what I got to work on Apache 2.2:
<FilesMatch /include(/?|/.*)>
Order allow,deny
Deny from all
</FilesMatch>
RedirectMatch 404 ^/include(/?|/.*)$
This handles these cases:
/include 404
/include/ 404
/include/config.inc 404
I had to change the FilesMatch part in order for the /include part to work properly.
EDIT:
The match line also works without the <FilesMatch> section in .htaccess and gives the expected results.
这篇关于问题403重定向禁404未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!