首页 文章

htaccess rewriteCond使用自定义http头

提问于
浏览
2

这有一千个线程,但我必须遗漏一些东西,因为我无法让它工作 .

我的nginx负载均衡器解密SSL流量并将其(通过Varnish)代理到内容服务器 . 它为代理请求添加了一个自定义标头:

proxy_set_header "IS-HTTPS" "1";

我可以从内容服务器中查看此HTTP标头:

<?php
var_dump($_SERVER["HTTP_IS_HTTPS"]);
?>

这将在HTTPS连接上输出 string(1) "1" ,在HTTP上输出 NULL .

所以,我的.htaccess规则:

RewriteCond%{HTTP:IS_HTTPS}!=“1”RewriteRule ^(securebit . *)$ https://% / $ 1 [R = 301,L]

不行 . 刚进入重定向循环 .

(注意:“//%”中的空格不存在.StackOverflow验证正在落在它上面 . )

也没有:

RewriteCond%{HTTP:IS_HTTPS}!= 1

RewriteCond%{HTTP:IS_HTTPS}!1

RewriteCond%{HTTP:HTTP_IS_HTTPS}!=“1”

RewriteCond%{HTTP:HTTP_IS_HTTPS}!= 1

RewriteCond%{HTTP:HTTP_IS_HTTPS}!1

我犯的是什么简单,明显和令人沮丧的错误?

2 回答

  • 3

    当在http和https端口上侦听的nginx将流量转发到本地apache实例时,我遇到了类似的问题 .

    在nginx配置中,我添加了:

    proxy_set_header X-Request-Protocol $scheme; #http or https
    

    在.htaccess文件中我添加了这个:

    RewriteEngine On
    RewriteCond %{HTTP:X-Request-Protocol} ^http$
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
    
  • 1

    你设置“IS-HTTPS”并检查“IS_HTTPS”?

相关问题