简体   繁体   中英

how can i access custom headers from an htaccess file?

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.

So I got HA proxy to add a custom header to send to apache (X-Forwarded-Proto = http or 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.

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?

You can use this rule:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM