我想重写以下内容
http://example.com
http://www.example.com
https://www.example.com
到
https://example.com
尝试使用
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
似乎无法正常工作
答案 0 :(得分:0)
您可以使用:
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]
答案 1 :(得分:0)
我说最容易做的就是写两条规则:
# First make sure HTTPS is being used
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Then make sure www isn't being used
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]