2012-02-28 69 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