RewriteEngine on RewriteCond %{HTTPS}_%{HTTP_HOST} ^(?|off_(?:www\.)?(.*)|on_www\.(.*)) [NC] RewriteRule .* https://%1/$0 [R=301,L]