【问题标题】:Redirecting subdomain to another subdomain, as variable将子域重定向到另一个子域,作为变量
【发布时间】:2014-09-17 09:17:45
【问题描述】:

我已经阅读了所有关于 .htaccess 的教程,但仍然不知道:

  • 我可以将子域作为变量重定向到另一个子域吗?

.htaccess 现在看起来是这样的:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*domain.com$ [NC]
RewriteRule ^(.*)$ http://anotherdomain.com/ [R=301,L]

我要重定向:

subdomain.domain.com

收件人:

subdomain.anotherdomain.com 

未指定子域。

所以它应该重定向:

subdomain1.domain.com

收件人:

subdomain1.anotherdomain.com

还有:

subdomain2.domain.com 

收件人:

subdomain2.anotherdomain.com

还有:

subdomain3.domain.com 

收件人:

subdomain3.anotherdomain.com

等等……

是否可以将subdomainx 传递给$1,然后重定向到$1.anotherdomain.com

【问题讨论】:

    标签: php apache .htaccess redirect


    【解决方案1】:

    你可以使用:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
    RewriteRule ^ http://%1.anotherdomain.com%{REQUEST_URI} [R=301,L,NE]
    

    【讨论】:

    • OK 它的工作,但为什么它将我从 subdomain1.domain.com 重定向到 subdomain1.anotherdomain.com//
    • 但这正是你所需要的:subdomain1.domain.com to subdomain1.anotherdomain.com
    • 哦,抱歉,我没有意识到我将其保留为 /%{REQUEST_URI} 而不是 %{REQUEST_URI}。谢谢@Prix。
    猜你喜欢
    • 1970-01-01
    • 2023-02-14
    • 1970-01-01
    • 1970-01-01
    • 2019-01-12
    • 2013-08-04
    • 2012-03-14
    • 1970-01-01
    相关资源
    最近更新 更多