使用的.htaccess强制HTTPhtaccess、HTTP

2023-09-02 09:40:31 作者:絕版ァ愛戀♂

这是剧本我现在,我怎么有我的剧本强制所有通信HTTP,目前它正在做的完全相反,它迫使所有流量HTTPS。

  RewriteEngine叙述上
的RewriteCond%{} HTTPS!=上
重写规则^的https://%{HTTP_HOST}%{REQUEST_URI} [L,R = 301]
 

我也尝试这样做,也没有工作。

  RewriteEngine叙述上
的RewriteCond%{HTTP}!=上
重写规则^的http:// {%HTTP_HOST}%{REQUEST_URI} [L,R = 301]
 
网站由http升级为https图文教程

我得到这个错误:

  

发生太多的重定向尝试打开www.blankpage.com。

解决方案

您需要检查的HTTPS是在

  RewriteEngine叙述上
的RewriteCond%{} HTTPS上
重写规则^的http:// {%HTTP_HOST}%{REQUEST_URI} [L,R = 301]
 

而如果是在(%{} HTTPS对),重定向到的http:// 。没有所谓的mod_rewrite的变量%{HTTP} ,只有%{HTTPS} 可以是on或关闭。

为什么你都拿到了太多的原因重定向错误的原因是:

 的RewriteCond%{HTTP}!=上
 

始终为true不管请求是HTTP或HTTPS,因为变量不存在,它会的永远的等于上。因此,即使该请求是HTTP,你一直得到重定向到相同的URL(HTTP)。

This is the script I have right now, how do I have my script force all traffic to http, currently it is doing the exact opposite, it is forcing all traffic to https.

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

I've also tried this and it didn't work

RewriteEngine On
RewriteCond %{HTTP} !=on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I got this error:

Too many redirects occurred trying to open www.blankpage.com .

解决方案

You want to check that HTTPS is on:

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

And if it is on (%{HTTPS} on), redirect to http://. There is no mod_rewrite variable called %{HTTP}, only %{HTTPS} which can be "on" or "off".

The reason why you were getting the too many redirects error is because:

RewriteCond %{HTTP} !=on

is always true no matter if the request is http or https, since the variable doesn't exist, it will never be equal to "on". Therefore, even if the request is http, you keep getting redirected to the same URL (http).