如何将伪造的 .htaccess 路径从 403 重定向到 404

How to redirect fake .htaccess path from 403 to 404

在我的 Drupal 网站上,如果我去伪造 url,例如:mysite.com/.htacess/nothing-here 我会收到 403 禁止访问(永远不会访问 Drupal)。有没有办法可以将其重定向到 404 而不是 403?

为了将服务器 403 捕获为自定义 404,您需要使用 ErrorDocument 指令(假设您使用的是 Apache HTTP 服务器):

In the event of a problem or error, Apache httpd can be configured to do one of four things :

  • output a simple hardcoded error message
  • output a customized message
  • internally redirect to a local URL-path to handle the problem/error
  • redirect to an external URL to handle the problem/error

所以要让 Drupal 处理文档,请设置以下 (httpd.conf) :

ErrorDocument 403 /index.php

注意:发送错误重定向时,附加 environment variables 可用:这些变量是通过在原始 REDIRECT_ 之前提供给原始请求的 header 生成的=25=]名字。这为错误文档提供了原始请求的上下文(例如 REDIRECT_URLREDIRECT_STATUSREDIRECT_QUERY_STRING)。