VirtualHosts 404 用于隐藏文件

发布于 2024-11-08 04:06:58 字数 751 浏览 0 评论 0原文

我正在使用一个友好的 url 解决方案,我通过 VirtualHosts 中的以下几行实现,

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ script.php?$1

因此我可以拥有类似于 http://example.com/something/something/else/other/things/

但是我如何向请求任何具有以 / 开头的文件夹的 url 的用户发送 404 状态。 (它不一定存在)

Example: http://example.com/.svn/this/should/be/404
Example: http://example.com/other/things/.cannot/access/here
Example: http://example.com/this/should/be/.denied

不应被拒绝的示例:

Example: http://example.com/t.his/is/ok

我尝试使用 FilesMatch 和 DirectoryMatch,但这更多的是虚拟路径,我无法让它工作。感谢您的帮助

I'm using a friendly url solution that i achieve with the following lines in VirtualHosts

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ script.php?$1

So i can have url's like http://example.com/something/something/else/other/things/

But how could i send a 404 status to the user who requests any url that has a folder starting with /. (it doesn't have to exist)

Example: http://example.com/.svn/this/should/be/404
Example: http://example.com/other/things/.cannot/access/here
Example: http://example.com/this/should/be/.denied

Examples that shouldn't be denied:

Example: http://example.com/t.his/is/ok

I've tried playing with FilesMatch and DirectoryMatch but this is more of a virtual path and i couldn't get it to work. Thank you for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

允世 2024-11-15 04:07:02

如果我理解这个问题,您是否希望在有人尝试访问隐藏或目录时抛出 404 错误?如果是这样,以下将这样做,但我不能说它对不存在的文件起作用。

重写规则“(^|/)。” - [R=404,L]

HTML5 Boilerpplate 有一个非常漂亮且文档齐全的 .htaccess 文件,我建议您检查一下。 http://html5boilerplate.com/

If I understand the question, you are looking to throw a 404 error anytime some tries to access a hidden or directory? If so the following will do so, though I can't say it works against no existent files.

RewriteRule "(^|/)." - [R=404,L]

HTML5 Boilerpplate has a very nice and well documented .htaccess file, I would recommend checking that out. http://html5boilerplate.com/

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