0

这是我的设置

  • 主域名:foo.com
  • 子域名:sub.foo.com
  • 附加域:bar.com

Root 上子域的目录结构是这样的:

sub/- 对于子域(这是默认值)

现在我在根目录中为 bar.com 创建一个子文件夹

bar/- 对于 bar.com

并创建了以下规则

RewriteCond %{HTTP_HOST} bar.com
RewriteCond %{REQUEST_URI} !bar/
RewriteRule ^(.*)$ bar/$1 [L]

结果会是。

  • sub.foo.com - 子/
  • bar.com - 酒吧/
  • bar.com/bar - bar/(我该如何解决这个问题?让它重定向到 bar.com?
  • bar.com/sub - sub/ (我该如何解决这个问题?让它重定向到 sub.foo.com?
  • foo.com/bar - bar/ (我该如何解决这个问题?让它重定向到 bar.com ?
  • foo.com/sub - sub/ (我该如何解决这个问题?让它重定向到 sub.foo.com?

所以底线是我不希望用户直接访问目录树上的子目录。这可能吗?如何?

编辑:请不要开始讲虚拟主机,我无权访问此服务器上的 httpd.conf

4

1 回答 1

0

In the main site's .htaccess:

RewriteCond %{HTTP_HOST} 

RewriteCond %{HTTP_HOST} www.foo.com
RewriteCond %{REQUEST_FILENAME} ^bar
RewriteRule ^bar/(.*)$ http://www.bar.com/$1 [R=301,L,QSA]

RewriteCond %{HTTP_HOST} www.foo.com
RewriteCond %{REQUEST_FILENAME} ^sub
RewriteRule ^sub/(.*)$ http://sub.foo.com/$1 [R=301,L,QSA]

The other 2 sites, being hosted from subdirectories should not ever have a need for trying to map away from something like bar.com/bar/... with this setup.

In the bar.com site you can do this:

RewriteBase /
RewriteCond %{REQUEST_FILENAME} ^bar/(.*)$
RewriteRule .* %1 [R=301,L,QSA]

RewriteRule ^bar/?$ / [R=301,L,QSA]

RewriteCond %{HTTP_HOST} www.bar.com
RewriteCond %{REQUEST_FILENAME} ^sub
RewriteRule ^sub/(.*)$ http://sub.foo.com/$1 [R=301,L,QSA]

For sub.foo.com you can do this:

RewriteBase /
RewriteCond %{REQUEST_FILENAME} ^sub/(.*)$
RewriteRule .* %1 [R=301,L,QSA]

RewriteRule ^sub/?$ / [R=301,L,QSA]

RewriteCond %{HTTP_HOST} sub.foo.com
RewriteCond %{REQUEST_FILENAME} ^bar
RewriteRule ^bar/(.*)$ http://www.bar.com/$1 [R=301,L,QSA]
于 2013-07-12T22:00:18.067 回答