Apache config:返回单个<Location>的404

是否可以让Apache自动使用Location标签为单个URL返回一个404页面?

<Location "/some/url"> # ??? </Location> 

没有mod_rewrite或其他模块的首选解决scheme。

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

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

 Redirect 404 /your/url/path 

你在你的虚拟主机中使用这个,不需要把它放在一个Location块中。

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

 RedirectMatch 404 ^/your/url/path$ 

这个和更多可以在mod_alias文档中读取

显然你可以使用一个RewriteRule (请确保你的RewriteEngine已经启用):

 RewriteRule ^/forbidden_ /nonexistent [L] 

从Apache邮件列表归档中的“ 返回404 for specific url? ”中获得这些信息。