14

I have an apache server behind a (simple amazon) load balancer. I want to redirect any incoming traffic that is not 443 to 443. I would prefer it to use just one apache virtual host. So I'm trying to detect that if the HTTP_X_FORWARDED_PORT header is not 443.

I've checked the RewriteCond docs and it only works with a limited set of HTTP headers.

Basically what I'm doing is this:

<VirtualHost *:80> ServerName www.example.com RewriteEngine On RewriteCond %{HTTP_X_FORWARDED_PORT} !=443 RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] .... </VirtualHost> 

But RewriteCond doesn't recognize HTTP_X_FORWARDED_PORT.

Is there any other way to accomplish this (with just one VirtualHost)? (some type of incoming header check?)

Thanks, Lance

1 Answer 1

16

A little further down the RewriteCond document:

%{HTTP:header}, where header can be any HTTP MIME-header name

So, you can do it, just not in quite the same form as the pre-extracted headers.

Try this:

RewriteCond %{HTTP:X-Forwarded-Port} !=443 RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] 
1
  • 1
    Another example with an IP address in a header passed by SiteLock CDN: RewriteCond %{HTTP:X-Forwarded-For} !=123.45.67.89 Commented Aug 26, 2015 at 16:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.