Skip to content

Instantly share code, notes, and snippets.

@maxkostinevich
Created February 27, 2015 08:44
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 maxkostinevich/99b46618c00cb8cb7bc0 to your computer and use it in GitHub Desktop.
Save maxkostinevich/99b46618c00cb8cb7bc0 to your computer and use it in GitHub Desktop.
Force HTTPS for main domain
# Force HTTPS for the main domain
# Replace DOMAIN.COM with your domain name
RewriteEngine On
RewriteCond %{HTTPS} off
# Only redirect to https if the main domain (not subdomain) is matched
# case-insensitively in HTTP_HOST
RewriteCond %{HTTP_HOST} ^DOMAINNAME\.COM$ [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Disable force HTTPS for subdomains
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?DOMAINNAME\.COM$ [NC]
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment