2012-02-28 138 views
3

我有一个旧网址(test.me.com),我想将其重定向到www.me.com在.htaccess中重定向https和http

所以我加入这行到我的.htaccess文件:

RewriteRule ^(.*)$ http://www\.me\.com/$1 [L,R=301] 

但事实证明,谷歌已经收录一些页面。由于我有SSL证书,完整的网址是https://test.me.com。所以上面的重定向不会影响https文件...

我试过这个,但没有运气。

RewriteCond %{HTTPS} =on 
RewriteRule ^(.+)$ - [env=ps:https] 
RewriteCond %{HTTPS} !=on 
RewriteRule ^(.+)$ - [env=ps:http] 

# redirect urls with index.html to folder 
RewriteCond %{HTTP_HOST} ^test.me.com [NC] 
RewriteRule ^.*$ %{ENV:ps}://www.me.com/%1 [R=302,L] 

如何配置这两个http://test.me.comhttps://www.test.com被重定向到http://www.me.com我的.htaccess文件?

回答

2
# redirect https requests or request on test.me.com to http://www.me.com 
RewriteCond %{HTTPS} =on [OR] 
RewriteCond %{HTTP_HOST} ^test\.me\.com$ [NC] 
RewriteRule ^(.*)$ http://www.me.com/$1 [R=301,L] 

或者替代也重定向至me.com www.me.com

RewriteCond %{HTTPS} =on [OR] 
RewriteCond %{HTTP_HOST} !^www\.me\.com$ [NC] 
RewriteRule ^(.*)$ http://www.me.com/$1 [R=301,L] 
+0

谢谢您的回答。但不应该在你的替代解决方案中的第二行是这样的:'RewriteCond%{HTTP_HOST}!^ test \ .me \ .com $ [NC]' – Michiel 2012-02-29 10:37:04

+0

nope。 。 。 。 。 。 – Gerben 2012-02-29 11:55:32

+0

'test.me.com'在哪里被重定向? – Michiel 2012-02-29 12:35:46