2014-10-07 136 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