Apache 配置:单个 <Location> 返回 404

And*_*Dog 11 configuration http-status-code-404 apache-2.2

是否可以让 Apache 使用位置标签自动返回单个 URL 的 404 页面?

<Location "/some/url">
    # ???
</Location>
Run Code Online (Sandbox Code Playgroud)

首选没有 mod_rewrite 或任何其他模块的解决方案。

hob*_*ave 17

“没有任何模块”的唯一解决方案是不存在资源。如果该位置不存在,则 Apache 将返回 404。

否则,您将需要使用 mod_alias 或 mod_rewrite。mod_alias 是更简单、更有效的解决方案:

Redirect 404 /your/url/path
Run Code Online (Sandbox Code Playgroud)

你在你的虚拟主机中使用它,没有必要把它放在一个位置块中。

RedirectMatch如果您不想匹配以下 URL,也可以使用该指令/your/url/path

RedirectMatch 404 ^/your/url/path$
Run Code Online (Sandbox Code Playgroud)

可以在mod_alias 文档中阅读更多内容