Apache HTACCESS返回404代码,即使在不使用重写mod的情况下存在页面:

发布于 2025-02-03 17:12:29 字数 70 浏览 1 评论 0原文

为了保护我的服务器免受机器人的侵害,如果请求某些文件,即使它们存在,但不使用重写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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

街角卖回忆 2025-02-10 17:12:29

您可以使用mod_alias redirect(或redirectMatch)指令。

例如:

Redirect 404 /file1.html
Redirect 404 /file2.html

这实际上并没有像外部3xx重定向一样触发“重定向”。如果要求其中一个URL(无论该文件是否存在),它将发送404响应。

参考:

如果这些URL存在模式,则使用redirectMatch指令,该指令与正则匹配,而不是使用简单的前缀匹配。例如,要为所有请求提供404,请/secret subdirectory(以及所有文件),然后使用以下内容:

RedirectMatch 404 ^/secret($|/)

自定义404响应使用errordocument指令:

ErrorDocument 404 /error-docs/404.html

You can use a mod_alias Redirect (or RedirectMatch) directive.

For example:

Redirect 404 /file1.html
Redirect 404 /file2.html

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:

RedirectMatch 404 ^/secret($|/)

To customise the 404 response use an ErrorDocument directive:

ErrorDocument 404 /error-docs/404.html
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文