Skip to content

Instantly share code, notes, and snippets.

@donbrae
Last active June 4, 2020 21:18
Show Gist options
  • Save donbrae/375f28cbfc82da87f9ae701ff8ae93ca to your computer and use it in GitHub Desktop.
Save donbrae/375f28cbfc82da87f9ae701ff8ae93ca to your computer and use it in GitHub Desktop.
# HTTPS redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
</IfModule>
# END HTTPS
# Force non-www SSL
# https://simonecarletti.com/blog/2016/08/redirect-domain-http-https-www-apache/
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment