Skip to content

Instantly share code, notes, and snippets.

@brentini
Created May 29, 2018 20:24
Show Gist options
  • Save brentini/0cd4a55a339944724cfd60f8c07a94d4 to your computer and use it in GitHub Desktop.
Save brentini/0cd4a55a339944724cfd60f8c07a94d4 to your computer and use it in GitHub Desktop.
Forcing SSL and WWW using .htaccess #htaccess #apache #ssl
RewriteEngine on
# Force www: from http://stackoverflow.com/a/4958847/1078583
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Force SSL: From http://stackoverflow.com/q/24322035/
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment