.htaccess for no-www and yes-www

Xiao-Hu Tai
2018-07-20T08:28:14Z

.htaccess

| # -- no-www --
| RewriteCond %{SERVER_PORT} ^80$
| RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
| RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
| RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
|
|
| # -- yes-www --
| RewriteCond %{SERVER_PORT} ^80$
| RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
| RewriteCond %{HTTP_HOST} !^www [NC]
| RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [R=301,L]