.htaccess:阻止物理目录 url,但允许该 url 间接通过子域
因此,出于安全原因,我想禁止 http://www.domain.com/directory/
但仅允许通过 http://subdomain.domain.com/directory/ 访问该物理目录
简单的方法是只移动目录,但我不能这样做,因为它会破坏应用程序,那么我该如何使用 .htaccess 来做到这一点?
我已经使用以下方法暂时阻止了它:
RedirectMatch 301 ^/directory/$ http://www.domain.com/
但是当然,在任何一种情况下都会重定向子目录,所以我想我可以只输入:
RedirectMatch 301 ^http://www.domain.com/directory/$ http://www.domain.com/
或类似的东西,但它不起作用...建议?
So for security reasons, I want to disallow http://www.domain.com/directory/
but allow that physical directory only through http://subdomain.domain.com/directory/
The simple way would be to just move the directory, but I can't do it because it breaks the application, so how would I do this with .htaccess?
I've temporarily blocked it using:
RedirectMatch 301 ^/directory/$ http://www.domain.com/
But of course that redirects the subdirectory in either case, so what I'd think is I could just put:
RedirectMatch 301 ^http://www.domain.com/directory/$ http://www.domain.com/
or something similar but it doesn't work... suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 RewriteCond 来完成此操作:
虽然更好,但我建议使用相同的文档根创建另一个虚拟主机。因此,在您的主服务器配置中,
当 Apache 不必解析
.htaccess
文件时,您的效率会更高。You can do it with a
RewriteCond
:Although better yet, I would recommend creating another virtual host with the same document root. So in your main server configuration, you'd have
It's more efficient when Apache doesn't have to parse the
.htaccess
files.