From a4652d95288d6f06fa9cf64bb32993ed3630aed9 Mon Sep 17 00:00:00 2001 From: KeenRivals Date: Mon, 9 Feb 2015 09:47:05 -0500 Subject: [PATCH] Snippet for forcing HTTPS when behind a proxy. --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 33683b3..22969d9 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ A collection of useful .htaccess snippets, all in one place. I decided to create - [Force www in a Generic Way](#force-www-in-a-generic-way) - [Force non-www](#force-non-www) - [Force HTTPS](#force-https) + - [Force HTTPS Behind Proxy](#force-https-behind-proxy) - [Force Trailing Slash](#force-trailing-slash) - [Redirect a Single Page](#redirect-a-single-page) - [Redirect an Entire Site](#redirect-an-entire-site) @@ -69,6 +70,13 @@ RewriteCond %{HTTPS} !on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} ``` +### Force HTTPS Behind Proxy +Useful if you have a proxy in front of your server performing TLS termination. +``` apacheconf +RewriteCond %{HTTP:X-Forwarded-Proto} !https +RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} +``` + ### Force Trailing Slash ``` apacheconf RewriteCond %{REQUEST_URI} /+[^\.]+$ @@ -335,4 +343,4 @@ AddDefaultCharset utf-8 # Force UTF-8 for a number of file formats AddCharset utf-8 .atom .css .js .json .rss .vtt .xml ``` -[Source](http://h5bp.com) \ No newline at end of file +[Source](http://h5bp.com)