我对 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/
那么,如何使其可缓存?
最佳答案
http://xxxx.com/ is a non-cacheable redirect to https://xxxx.com/
错误说明了一切。要使其在浏览器中永久可缓存,请使用 R=301
:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
关于apache - 使用 htaccess 将用户从 http 重定向到 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25797590/