Skip to content

Instantly share code, notes, and snippets.

@wesort
Last active May 17, 2018 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesort/28dc0fc3d688f8ff88d5af4a385b0384 to your computer and use it in GitHub Desktop.
Save wesort/28dc0fc3d688f8ff88d5af4a385b0384 to your computer and use it in GitHub Desktop.
HTTPS: htaccess redirect from http, http + www, and https + www
RewriteEngine On
#
# Redirect all http and www traffic to https non-www URL
# Ref for all but first line: https://simonecarletti.com/blog/2016/08/redirect-domain-http-https-www-apache/
# Ref to correct for Webfaction using nginx ssl proxy: cpbotha.net... https://goo.gl/Vnbdw9
#
RewriteCond %{HTTP:X-Forwarded-SSL} !on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment