Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>

        RewriteEngine On
        RewriteCond %{HTTP_X_FORWARDED_PORT} !=443
        RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]


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
up vote 8 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
Another example with an IP address in a header passed by SiteLock CDN: RewriteCond %{HTTP:X-Forwarded-For} != – Liam Aug 26 '15 at 16:22

Your Answer


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.