子域名重定向到新域名 [英] Redirect Subdomain to new domain
本文介绍了子域名重定向到新域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨试图获得301重定向工作,遇到了麻烦。我需要sub.domain1.com重定向到www.domain2.com,并确保任何文件名或参数得到送过来吧。
Hi guys trying to get a 301 redirect working and having trouble. I need to redirect sub.domain1.com to www.domain2.com and make sure that any file names or parameters get sent over with it.
这是我试图:
RewriteCond %{HTTP_HOST} ^domain1.com [NC]
RewriteRule ^(.*)$ http://www.domain2.com/$1 [L,R=301]
我也试过这样的:
I also tried this:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^sub\.domain1\.com$ /www.domain2.com? [R=301,NE,NC,L]
我在哪里搞乱?
推荐答案
有关的RewriteRules经验法则:从最复杂的那么复杂。
而且不要忘了QSA指令(QSA =查询字符串附加=确保任何文件名或参数得到送过来吧)
Rule of thumb for rewriterules: from the most complex to the less complex. And don't forget the QSA directive (QSA = Query String Append = "make sure that any file names or parameters get sent over with it")
RewriteCond %{HTTP_HOST} ^sub\.domain1\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain2.com/$1 [QSA,R=301,L]
告诉我,如果它的工作原理。
Tell me if it works.
这篇关于子域名重定向到新域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文