VirtualHosts 404 用于隐藏文件
我正在使用一个友好的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解这个问题,您是否希望在有人尝试访问隐藏或目录时抛出 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/