0

我接近实现我的目标,但我无法为我的问题找到正确的解决方案。

我为通配符子域编写了以下规则:

#remove www.
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain\.com/$1 [R=301,L]

#rewrite subdomains to /club/<clubname as defined by subdomain>/<whatever was here before>
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/club/%1/$0 [NC,L]

这非常接近我的要求,即如果我转到http://alpha.domain.com/some/string/here,则 URL 将被重写为http://domain.com/club/alpha/some/string/这里

然而

我希望浏览器中的网址仍然看起来像原始网址

提前谢谢了

编辑:我尝试将 PT 添加到最终规则中,但这不起作用,我收到 400 错误

EDIT2:对于任何有兴趣的人,我放弃了这行查询,而是使用 php 来读取子域中的文本。

4

1 回答 1

1

如果www.example.com子域使用与example.com域相同的虚拟主机,则可以通过使用相对路径来使用内部重写:

RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteCond $0 !^club/
RewriteRule ^(.*)$ club/%1/$0 [NC,L]

否则,您将需要一个代理:

RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/club/%1/$0 [NC,L,P]
于 2011-02-10T15:29:07.047 回答