Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.