As w3d mentioned in a comment, the #
signs need to be removed from the beginning of each line in order for the rules to take effect.
Also, you should update this:
RewriteCond %{HTTP_HOST} (.*).domain1.com
... so that it now looks something like this:
RewriteCond %{HTTP_HOST} ^(.+).domain1.com$
The ^
sign signifies the beginning of a value, and the $
signifies the end of a value.
The reason for replacing (.*)
with (.+)
is because theoretically you're telling your server that .domain1.com
is a valid domain name when you use (.*)
(when in fact there should at least be once character before the first dot).
The reason for the backslashes is to escape the dots inside the RewriteCond
. See this page for more info on rewrite conditions and rules.
Ultimately you might end up with something like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+).domain1.com$
RewriteRule ^(.*)$ http://%1.domain2.com/$1 [R=301,QSA,L]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…