繁体   English   中英

将子域重定向为另一个子域,作为变量

[英]Redirecting subdomain to another subdomain, as variable

我已经阅读了有关.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

您可以使用:

RewriteEngine On

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM