Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 438
DAB Avatar asked Jan 12 '14 00:01

DAB


People also ask

What can I do with an .htaccess file?

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.

Can you add custom HTTP headers?

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.

What is IfModule in Apache?

<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.


1 Answers

You can use this rule:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
like image 166
anubhava Avatar answered Oct 01 '22 09:10

anubhava