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

发布于 2024-09-25 04:26:46 字数 428 浏览 1 评论 0原文

我试图拒绝直接访问的人对子域目录的访问,而不是让他们直接浏览子域。例如,我希望人们能够访问 http://test.example.com 而不是 http://example.com/test。如果它们确实显示 403 Forbidden 错误。这可以通过 htaccess 实现吗?谷歌搜索但看不到有人这样做。主要目的是禁止他们直接访问内容。尝试了以下方法没有成功。

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

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 e.g I want people to be able to go to http://test.example.com and not http://example.com/test. If they do show a 403 Forbidden error. Is this possible through 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>

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

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

发布评论

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

评论(1

无声无音无过去 2024-10-02 04:26:46

您可以执行从 example.com/test/test.example.com 的永久重定向。这将确保每个人都可以访问 test.example.com 下的网站。这将更适合您的用户。

RewriteEngine On

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

如果你真的想显示 403 Forbidden,你可以这样做

RewriteEngine On

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

You can do a permanant redirection from example.com/test/ to test.example.com. This will make sure everyone visit your site under 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

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example.com [nc]
RewriteRule ^test/(.*)$ / [r=403,nc] 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文