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?
The . htaccess is an important WordPress core file often used to add, modify, and override server-level configurations, security, and performance parameters. In most cases, you can resolve server-level operational issues and challenges by simply updating/changing the rules in the . htaccess file.
If you want to set a custom HTTP headers on your server to be sent in your HTTP responses, the process is quite simple. We have outlined below the snippets required to add a custom header for both Apache and Nginx web servers.
<IfModule> is simply a directive that tests the condition "is the named module loaded by apache httpd" (in your example mod_expires). It allows people to produce conditional based configuration for different installations where certain modules may be present or not.
You can use this rule:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With