Apache HTACCESS返回404代码,即使在不使用重写mod的情况下存在页面:
为了保护我的服务器免受机器人的侵害,如果请求某些文件,即使它们存在,但不使用重写mod,我还是要返回404错误页面。有可能吗?
To protect my server from bots, I want to return a 404 error page if certain files are requested EVEN IF THEY EXIST but without using the rewrite mod. It is possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用mod_alias
redirect
(或redirectMatch
)指令。例如:
这实际上并没有像外部3xx重定向一样触发“重定向”。如果要求其中一个URL(无论该文件是否存在),它将发送404响应。
参考:
如果这些URL存在模式,则使用
redirectMatch
指令,该指令与正则匹配,而不是使用简单的前缀匹配。例如,要为所有请求提供404,请/secret
subdirectory(以及所有文件),然后使用以下内容:自定义404响应使用
errordocument
指令:You can use a mod_alias
Redirect
(orRedirectMatch
) directive.For example:
This doesn't actually trigger a "redirect", as in an external 3xx redirect. It sends the stated 404 response if one of the URLs is requested (regardless of whether that file exists or not).
Reference:
If there is a pattern to these URLs then use a
RedirectMatch
directive instead, which matches against a regex rather than using simple prefix-matching. For example, to serve a 404 for all requests to the/secret
subdirectory (and all files within) then use the following:To customise the 404 response use an
ErrorDocument
directive: