Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jopfre/8c791000038d00faad2637e9ed8134a6 to your computer and use it in GitHub Desktop.
Save jopfre/8c791000038d00faad2637e9ed8134a6 to your computer and use it in GitHub Desktop.
#http://stackoverflow.com/a/27029144
RewriteEngine On
# match any URL with www and rewrite it to https without the www
RewriteCond %{HTTP_HOST} ^(www\.)(.*) [NC]
RewriteRule (.*) https://%2%{REQUEST_URI} [L,R=301]
# match urls that are non https (without the www)
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(www\.)(.*) [NC]
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