2014-10-07 135 views
7

我最近做了我的網站的谷歌的PageSpeed分析,並收到以下消息:避免登陸頁面重定向使用SSL

避免登陸頁面重定向

你的頁面有2個重定向。重定向在頁面加載之前引入額外的延遲 。

避免將目標網頁重定向到以下重定向 網址鏈。

http://example.net/

https://example.net/

https://www.example.net/

有什麼我可以做這個(如修改以某種方式我htaccess文件),或者這是一個不可避免的後果是什麼?

這是我的htaccess以防萬一:

RewriteCond %{HTTPS} off 
# First rewrite to HTTPS: 
# Don't put www. here. If it is already there it will be included, if not 
# the subsequent rule will catch it. 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
# Now, rewrite any request to the wrong domain to use www. 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

回答

4

您可以通過使用OR標誌

RewriteCond %{HTTPS} off [OR] 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC] 
RewriteRule^https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
+1

由於兩個重定向合二爲一。這應該解決上述PageSpeed投訴,還是僅僅是您提出的一般性優化? – 2014-10-07 15:40:13

+1

@JohnRoberts沒有辦法避免登陸頁面重定向,因爲你想強制執行一個「www」和「https://」方案,但至少這只是一個重定向而不是2。 – 2014-10-07 15:41:20