Skip to content

Instantly share code, notes, and snippets.

@tecking
Forked from fillipetech/force-https-htaccess.txt
Created November 28, 2018 08:45
Show Gist options
  • Save tecking/9d946a18d25de255e09af49d32f226e3 to your computer and use it in GitHub Desktop.
Save tecking/9d946a18d25de255e09af49d32f226e3 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