重定向子域到相同的子域名但不同的域名 [英] redirect subdomain to same subdomain name but different domain name
问题描述
我有一个名为exmaple.com的网站,其中有很多子域
i have site called exmaple.com have a lot of subdomains
test1 , test2 , test2.example.com
我该如何重定向具有确切子域名但又重定向到另一个域名的子域名
how could i redirect subdomains with exact subdomain but to another domain name for example
test1 , test2 , test3.example.net
谢谢
推荐答案
使用%1%2等从RewriteCond中获取正则表达式匹配组.
Use %1 %2 etc. to grab regex-match groups from the RewriteCond.
您可能知道,$ 1 $ 2匹配RewriteRule中的正则表达式组
As you probably know, $1 $2 matches regex groups from the RewriteRule
在我的脑海中,使用mod_rewrite活动非常简单:
Off the top of my head, this is pretty straightforward with mod_rewrite active:
RewriteEngine On
RewriteCond %{REQUEST_HOST} (.+)\.example\.com
RewriteRule (.*) http://%1.example.net$1 [R,QSA]
这假定您正在从单个虚拟主机提供所有这些子域,但是如果不是,则可以将此规则集分别复制到每个用户的配置或.htaccess中.
This assumes that you are serving all those subdomains from a single virtual host, but if you aren't, you can just copy this ruleset into each one's config or .htaccess individually.
这篇关于重定向子域到相同的子域名但不同的域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!