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
thanks
This may work. Put it in your .htaccess.
RewriteEngine On
RewriteCond %{HTTP_HOST} (.*).example.com
RewriteRule (.*) http://%1.example.net/$1 [R=301,QSA,L]
Haven't tested it, but it should give you a start.
Use %1 %2 etc. to grab regex-match groups from the RewriteCond.
As you probably know, $1 $2 matches regex groups from the RewriteRule
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]
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.
来源:https://stackoverflow.com/questions/10507548/redirect-subdomain-to-same-subdomain-name-but-different-domain-name