如何从htaccess文件访问自定义标头?

时间:2022-06-15 15:06:22

I am currently using HA proxy in front of an apache setup. Since HA proxy is doing the https termination, i can't use apache to tell if it's https or http.

我目前在apache设置前使用HA代理。由于HA代理正在进行https终止,我无法使用apache来判断它是https还是http。

So I got HA proxy to add a custom header to send to apache (X-Forwarded-Proto = http or https)

所以我有HA代理添加自定义标头发送到apache(X-Forwarded-Proto = http或https)

In my htaccess i would like to do a redirect based on that header, but it looks like i can only access the headers apache has specifically listed.

在我的htaccess中,我想基于该标题进行重定向,但看起来我只能访问apache已经专门列出的标题。

for example i can't do:
RewriteCond %{HTTP_X_FORWARDED_PROTO} !^https$
RewriteRule ^(.*) https://%{HTTP_HOST}$1

is there another way i can test the header?

还有另一种方法可以测试标题吗?

1 个解决方案

#1


5  

You can use this rule:

您可以使用此规则:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]

#1


5  

You can use this rule:

您可以使用此规则:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]