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 want to force Apache to redirect all traffic through HTTPS:

# Redirect HTTP traffic to HTTPS.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://mypublicip/$1 [R=301,L]

Unfortunately, this does not work when I am trying to access my website from my local network using my Web server's private IP. How could I work around this limitation?

share|improve this question
up vote 2 down vote accepted

mod_rewrite supports more variables like %{HTTPS}. For your requirement %{HTTP_HOST} is the way to go.

share|improve this answer
Do you mean something like RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]? – pyon Mar 22 '11 at 18:45

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.