Skip to content

Instantly share code, notes, and snippets.

@Tmeister
Last active March 20, 2019 20:51
Show Gist options
  • Save Tmeister/2200ad9b5c818fb67ca74dba8f27e724 to your computer and use it in GitHub Desktop.
Save Tmeister/2200ad9b5c818fb67ca74dba8f27e724 to your computer and use it in GitHub Desktop.
301 redirections to force naked domain with SSL
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(www.)?domain.com$ [NC]
RewriteRule . http://domain.com%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^(www.)?domain.com$ [NC]
RewriteRule . https://domain.com%{REQUEST_URI} [R=301,L]
#Other option
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment