使用SSL避免登陆页面重定向

Joh*_*rts 7 url performance .htaccess ssl redirect

我最近对我的网站进行了Google PageSpeed分析,并收到以下消息:

避免登陆页面重定向

您的页面有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]
Run Code Online (Sandbox Code Playgroud)

Jon*_*Lin 6

您可以使用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]
Run Code Online (Sandbox Code Playgroud)