简体   繁体   English

限制对Web目录的访问,但允许子域

[英]Restrict access to web directory but allow sub-domain

I am trying to deny access to a sub-domain directory from people accessing directly rather get them to browse to the sub-domain directly. 我试图拒绝直接访问的人访问子域目录,而不是让他们直接浏览到子域。 For eg I want people to be able to go to http://test.example.com and not http://example.com/test . 例如,我希望人们能够访问http://test.example.com而不是http://example.com/test If they do show a 403 Forbidden error. 如果他们确实显示403 Forbidden错误。 Is this possible through htaccess ? 这可能通过htaccess吗? Googled it but cant see anyone doing this. 谷歌搜索它,但看不到任何人这样做。 The main purpose being to disallow them from accessing the contents directly. 主要目的是禁止他们直接访问内容。 Tried the following to no success. 试过以下没有成功。

<Directory /test>
  Order Deny,Allow
  Deny from all
  Allow from .example.com
</Directory>

You can do a permanant redirection from example.com/test/ to test.example.com . 你可以从您永久重定向example.com/test/test.example.com This will make sure everyone visit your site under test.example.com . 这将确保每个人都在test.example.com下访问您的网站。 This would be more appropriate for your users. 这对您的用户更合适。

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example.com [nc]
RewriteRule ^test/(.*)$ http://test.example.com/$1 [r=301,nc] 

If you really want to show a 403 Forbidden, you can do this 如果你真的想要展示403 Forbidden,你可以这样做

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example.com [nc]
RewriteRule ^test/(.*)$ / [r=403,nc] 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM