注意:配置和错误更新更清晰。
我在Ubuntu上运行apach 2.4的网站有以下.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_HOST} ^(www\.)example1.com [OR]
RewriteCond %{HTTP_HOST} ^(www\.)example2.com
RewriteRule ^(.*)$ https://www.example2.com/$1 [L,R=301]
</IfModule>
如果我转到http://example2.com,http://www.example2.com or
http://www.example1.com it redirects to
https`
如果我转到http://example1.com
,则会保留为http。
是否有我遗漏的内容,以便仅使用基础/
网址重定向?
答案 0 :(得分:1)
问题在于这两个规则:
RewriteCond %{HTTP_HOST} ^(www\.)example1.com [OR]
RewriteCond %{HTTP_HOST} ^(www\.)example2.com
您需要添加?
才能使www.
成为可选:
RewriteCond %{HTTP_HOST} ^(www\.)?example1.com [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example2.com