Skip to content

Instantly share code, notes, and snippets.

@Zillionx
Last active September 13, 2019 13:13
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 Zillionx/1b001f94acfa4176550f74103049e66f to your computer and use it in GitHub Desktop.
Save Zillionx/1b001f94acfa4176550f74103049e66f to your computer and use it in GitHub Desktop.
.htaccess - HTTPS and www rewrite
RewriteEngine On
## https and www rewrite
# https to www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# https (no Cloudflare proxied)
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# https without www.
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://domain.tld%{REQUEST_URI} [R=301,L,NE]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment