2014-02-20 49 views
1

我的域名www.abc.com現在重定向到https://www.abc.co.uk重定向特定域到HTTPS

RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

這些代碼的工作正是我想要的。之後,我創建了一個子域。 www.x.abc.co.uk 現在我想重定向到http://x.abc.co.uk(不包括HTTPS)

我用這個

RewriteCond %{HTTP_HOST} ^x\.abc\.co\.uk [NC] 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

但瀏覽器說,它有重定向循環。

該怎麼辦?

回答

1

如果這些是兩個不同的htaccess文件,那麼試試這個。

RewriteEngine On 
#redirect www.x.abc.co.uk without www to http 
RewriteCond %{HTTP_HOST} ^www\.x\.abc\.co\.uk [NC] 
RewriteRule ^(.*)$ http://x.abc.co.uk%{REQUEST_URI} [L,R=301] 

我修改了你原來的規則,所以你沒有兩個重寫規則,仍然直接到www。

RewriteEngine On 
RewriteCond %{HTTP_HOST} !^www\. [OR] 
RewriteCond %{HTTPS} !^on$ 
RewriteRule ^(.*)$ https://www.abc.co.uk%{REQUEST_URI} [L,R=301] 
+0

+1需要額外的努力才能將2條規則合併爲一條。 – anubhava

相關問題