首页 文章

使用htaccess将用户从http重定向到https

提问于
浏览
2

我对htaccess一点也不熟悉 . 我需要Htaccess代码,它会将http重定向到https . 我使用下面的代码:

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

但主要的问题是,当我试图测试服务器速度时,我得到了以下建议:

To speed up page load times for visitors of your site, remove as many landing page
redirections as possible, and make any required redirections cacheable if possible.

http://xxxx.com/ is a non-cacheable redirect to https://xxxx.com/

那么,如何使其可缓存?

1 回答

  • 2

    http://xxxx.com/是一个不可缓存的重定向到https://xxxx.com/

    错误说明了一切 . 要使其在浏览器中永久缓存,请使用 R=301

    RewriteEngine On
    
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    

相关问题