Skip to content

Instantly share code, notes, and snippets.

@alrnz
Last active August 10, 2016 15:42
Show Gist options
  • Save alrnz/1b5af6b2004eeadffe3d1bb95dfbd948 to your computer and use it in GitHub Desktop.
Save alrnz/1b5af6b2004eeadffe3d1bb95dfbd948 to your computer and use it in GitHub Desktop.
Redirect http to https without checking HTTPS != on
# ----------------------------------------------------------------------
# | Forcing `https://` |
# ----------------------------------------------------------------------
# Redirect from the `http://` to the `https://` version of the URL.
# On my Server the %{HTTPS} !=on does not work and always redirects
# (infinite redirect loop with the "Too many redirects"-error)
<IfModule mod_rewrite.c>
RewriteEngine On
# does not work on my mittwald-server
#RewriteCond %{HTTPS} !=on
# use this check instead
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# in some environments it is necessary to use this:
# for the normal environment as fallback (e.g. DEV)
RewriteCond %{HTTPS} off
# some special kind of sorcery...
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment