Advanced HTACCESS Subdomain Redirection (foo.dom2.com to foo.dom1.com)

不打扰是莪最后的温柔 提交于 2019-12-05 14:54:57

You're on the right track with %{HTTP_HOST} but you need to use backreferences (%1, %2, etc) to access the match against it. You want to do something like this:

RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain2\.com$ [NC]
RewriteRule ^(.*)$ http://%2.domain1.com/$1  [L,R]

Note that if you try to access: http://www.sub.domain2.com/foo it will redirect you to http://sub.domain1.com/foo, The "www." of the original request is gone. If you want the www, change the rule to:

RewriteRule ^(.*)$ http://%1%2.domain1.com/$1  [L,R]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!