<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Put the protocol into the% {ENV: PROTOCOL} environment variable
RewriteRule ^ (. *) $ - [E = PROTOCOL: http]
RewriteCond% {https} ^ on $ [NC]
RewriteRule ^ (. *) $ - [E = PROTOCOL: https]
# If you need to remove www
RewriteCond% {SERVER_PORT} ^ 80 $
RewriteCond% {HTTP_HOST} ^ www \. (. *) [NC]
RewriteRule ^ (. *) $% {ENV: PROTOCOL}: //% 1% {REQUEST_URI} [R = 301, L]
RewriteCond% {HTTP_HOST} ^ www \. (. *) [NC]
RewriteRule ^ (. *) $% {ENV: PROTOCOL}: //% 1:% {SERVER_PORT}% {REQUEST_URI} [R = 301, L]
</ IfModule> Source: https://habr.com/ru/post/51629/
All Articles