【问题标题】:Transparent rewrite/Pass Through of wildcard subdomain通配符子域的透明重写/传递
【发布时间】:2011-02-08 23:33:21
【问题描述】:

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

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

#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/here

然而

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

在此先感谢

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

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

【问题讨论】:

    标签: apache mod-rewrite apache2 mod-auth-passthrough


    【解决方案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]
    

    【讨论】:

    • 谢谢,但我第一次收到错误 500,第二次收到 404
    • @Vanthel:您在哪里使用该规则?在文档根目录下的.htaccess文件中?
    • 那是正确的,这条规则是否可能会以某种方式发生冲突(在文件的更下方:RewriteRule .* index.php/$0 [PT])
    猜你喜欢
    • 1970-01-01
    • 2012-03-12
    • 2012-08-09
    • 2014-06-09
    • 1970-01-01
    • 2011-10-18
    • 2011-01-11
    • 1970-01-01
    • 2014-02-28
    相关资源
    最近更新 更多