Skip to content

Instantly share code, notes, and snippets.

@jonnitto
Last active November 9, 2017 14:16
Show Gist options
  • Save jonnitto/0be3c3a578f839691807a4b9b33b2f90 to your computer and use it in GitHub Desktop.
Save jonnitto/0be3c3a578f839691807a4b9b33b2f90 to your computer and use it in GitHub Desktop.
Top-level and subdomain based condition
# Force https
RewriteCond %{HTTP_HOST} !\.test$
RewriteCond %{HTTP_HOST} !\.prod$
RewriteCond %{HTTP_HOST} !^stage
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Force www
RewriteCond %{HTTP_HOST} !\.test$
RewriteCond %{HTTP_HOST} !\.prod$
RewriteCond %{HTTP_HOST} !^stage
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment