htaccess 命令阻止通过子目录访问主站点?
我的托管设置包含一个主域(映射到 Web 根目录),然后是多个插件域(每个域在 Web 根目录中都有自己的文件夹)。目前,您可以访问 www.masterdomain.com/addondomainsubdir 并到达与访问 www.addondomain.com 相同的页面(映射到 /public_html/addondomainsubdir)。我想防止这种情况发生,因此如果您访问 www.masterdomain.com/addondomainsubdir 那么它将执行 301 重定向到 www.addondomain.com。新的 addondomain.com 站点是单页站点,因此不必映射任何其他页面。
向 Web 根目录中的 htaccess 文件添加规则不会影响任何内容,因为子目录存在,这很奇怪,因为我认为即使存在匹配的子目录,htaccess 命令也应该起作用(我已经尝试了以下方法,当没有匹配的子目录时,它可以起作用) :
RewriteRule ^addondomainsubdir?$ http://www.addondomain.com [NC,R=301,L]
从逻辑上讲,考虑到它到达了这个目录,我想我需要在 addondomainsubdir 目录中的 htaccess 文件中添加一个命令,但是似乎没有任何效果(我已经设置了各种其他规则,并且它们工作正常)。
如果有人解释纠正这个问题的最佳方法,我将不胜感激?
非常感谢你的帮助,
戴夫
I have hosting setup with a master domain (mapped to the web root) and then a number of addon domains (each with their own folder within the web root). At the moment you can visit www.masterdomain.com/addondomainsubdir and reach the same page as you would if you visited www.addondomain.com (which maps to /public_html/addondomainsubdir). I want to prevent this so if you visit www.masterdomain.com/addondomainsubdir then it will do a 301 redirect to www.addondomain.com. The new addondomain.com site is a single page site so it does not have to map any additional pages.
Adding rules to the htaccess file in the web root does notaffect anything as the subdir exists which is wierd as i thought the htaccess command should work even if there is a matching subdir (i've tried the following which works when there's no matching subdir):
RewriteRule ^addondomainsubdir?$ http://www.addondomain.com [NC,R=301,L]
Logically given it's reaching this directory I figure i need to add a command within the htaccess file in the addondomainsubdir directory however nothing appears to have any effect (i've got various other rules setup and they work fine).
I would be massively grateful if anyone explain the best way to rectify this?
Thanks so much for your help,
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这是一篇旧帖子,但从未得到成功答复。因此,对于通过搜索找到此内容的所有人来说,这应该符合OP的要求。
将此行添加到您的
.htaccess
文件中:I know this is an old post, but it has never been successfully answered. So for all of you finding this via search, this should do what the OP is asking.
Add this line to your
.htaccess
file:在您的 .htaccess 中尝试以下规则:
Try these rules in your .htaccess:
我不会在主 .htaccess 中添加规则,而是为每个附加域创建一个 .htaccess,并将每个附加域放入各自的子目录中。
Instead of putting a rule in your main .htaccess, I would make make a .htaccess for each add-on domain, putting each one in the respective subdirectory.