Skip to content

Instantly share code, notes, and snippets.

@fillipetech
Created July 22, 2018 09:34
Show Gist options
  • Save fillipetech/b563baf8c5b42364a67e4b141935c718 to your computer and use it in GitHub Desktop.
Save fillipetech/b563baf8c5b42364a67e4b141935c718 to your computer and use it in GitHub Desktop.
Force https #https #security
RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{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