我需要将Apache 2.2服务器上的所有请求重定向到任何未找到404的目录。
例如:
/xyz
或/xyz/
会引发403 - >重定向到404 /xyz/sometext.txt
正常返回。 环顾四周,我发现了这篇文章:
Problem redirecting 403 Forbidden to 404 Not Found
RedirectMatch 404 ^/include(/?|/.*)$
/include 404 (instead of 403)
/include/ 404
/include/config.inc 404 (instead of 403)
然而,最后一个案例也返回404.此外,它只影响/ include /目录,我看起来更多的任何禁止目录。到目前为止,我有:
RedirectMatch 404 ^[\/[\w+]]+\/$
任何人都知道如何做到这一点?谢谢,
答案 0 :(得分:10)
要为今天导致403的任何请求返回404 not found
,您可以执行以下操作:
ErrorDocument 403 /404.php
然后在/404.php
中,您可以添加此行以向客户返回404状态:
<?php
# your custom 404 content goes here
# now make it return 404 status to browser
http_response_code(404);
?>
要将所有请求返回404,您可以执行以下操作:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ - [L,R=404]
答案 1 :(得分:0)
只要您的403错误文档在限制区域内,它就永远不会出现,它必须在拒绝访问区域之外。