Skip to content

Instantly share code, notes, and snippets.

@dejurin
Last active December 7, 2017 16:52
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 dejurin/f1d70e183985089fd3c36c5dd9c88587 to your computer and use it in GitHub Desktop.
Save dejurin/f1d70e183985089fd3c36c5dd9c88587 to your computer and use it in GitHub Desktop.
htaccess: redirect HTTP to HTTPS with without WWW
// without wwww
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
// with www
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
// read more https://simonecarletti.com/blog/2016/08/redirect-domain-http-https-www-apache/
// bitrix
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://example.com/$1 [R,L]
// all
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment