mod_rewrite到ssl不适用于example.com,但是为example.com/index.html

时间:2015-11-27 09:22:54

标签: apache .htaccess mod-rewrite

注意:配置和错误更新更清晰。

我在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>

是否有我遗漏的内容,以便仅使用基础/网址重定向?

1 个答案:

答案 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