使用htaccess的重定向从http用户到https重定向、用户、htaccess、https

2023-09-02 09:59:12 作者:神出鬼没→杀

我一点都不熟悉htaccess的。我需要的.htaccess code这将重定向HTTP到HTTPS。我使用低于code:

  RewriteEngine叙述上
的RewriteCond%{} HTTPS!上
重写规则HTTPS(*)://%{HTTP_HOST}%{REQUEST_URI}
 

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

 来加快页面加载时间为您的网站的访问者,删除尽可能多的登陆页面
重定向越好,并进行任何所需的重定向缓存如果可能的。

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

那么,如何使它可缓存?

解决方案   

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

错误说明了一切。为了使其在浏览器中使用 R = 301 永久缓存:

  RewriteEngine叙述上

的RewriteCond%{} HTTPS关闭
重写规则^的https://%{HTTP_HOST}%{REQUEST_URI} [L,R = 301,NE]
 
设置IIS7 http重定向到https

I am not at all familiar with htaccess. I need Htaccess code which will redirect http to https. I am using below code:

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

But main problem is, I am getting below suggestion, when trying to test server speed:

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/

So, how to make it cacheable ?

解决方案

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

Errors says it all. To make it permanently cacheable in browser use R=301:

RewriteEngine On

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