Skip to content

Instantly share code, notes, and snippets.

@townivan
Created July 15, 2019 12:59
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 townivan/542489a55d1f13480e34fc4c8d12cede to your computer and use it in GitHub Desktop.
Save townivan/542489a55d1f13480e34fc4c8d12cede to your computer and use it in GitHub Desktop.
htaccess which redirects http://domain, https://domain, http://www.domain to https://www.domain
# if host contains www - skip redirect to www
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule .? - [S=1]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# redirect all to https
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