php - 使用 .htaccess 强制 http

标签 php .htaccess

这是我现在拥有的脚本,我如何让我的脚本强制所有流量到 http,目前它正在做完全相反的事情,它强制所有流量到 https。

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

我也试过了,没用

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

我遇到了这个错误:

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

最佳答案

您想检查 HTTPS 是否开启:

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

如果它是打开的(%{HTTPS} on),重定向到 http://。没有名为 %{HTTP} 的 mod_rewrite 变量,只有 %{HTTPS} 可以是“on”或“off”。

您收到太多重定向错误的原因是:

RewriteCond %{HTTP} !=on
无论请求是 http 还是 https,

始终为真,因为该变量不存在,所以它永远不会等于“on”。因此,即使请求是 http,您也会不断被重定向到相同的 URL (http)。

关于php - 使用 .htaccess 强制 http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19230909/

相关文章:

用于获取页面的文件大小和加载时间的 PHP 函数

php - 在 Prestashop 中插入表 search_index 失败

php - 使用for循环将Mysql行转为html表

apache - htaccess 在 URL 中使用 PHP $_GET 方法重写规则? (从子子文件夹到根目录)

linux - 在 shell 脚本中使用 sed 替代不起作用

.htaccess - Mercurial 选择性地 hgignore htaccess 文件

php - 修改单个 RegEx 以匹配字符串中的中间项

javascript - 是否会使用 AJAX 发送 http_only cookie?

apache - .htaccess 处理某些字母

php - 禁止没有索引页的文件夹使用 403