# www.sample.com→sample.com
# RewriteEngine On
# RewriteCond %{HTTP_HOST} ^www\.sample\.com
# RewriteRule ^(.*) https://sample.com/$1 [R=301,L]
# http→https
# RewriteEngine on
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://sample.com/$1 [R=301,L]
# 上記結合(or)
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.sample\.com
RewriteRule ^(.*)$ https://sample.com/$1 [R=301,L]
実行結果:
1.http://www.sample.com→https://sample.com
OK
2.http://sample.com→https://sample.com
OK
3.https://www.sample.com→https://sample.com
NG
なぜ?