使用HTTPS进行ModRewrite

时间:2010-09-07 14:46:00

标签: .htaccess mod-rewrite canonical-link

我正在使用以下mod重写来确保不仅使用规范网址,还要确保使用HTTPS显示网站:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
// It think the problem must be here --^

RewriteCond %{HTTP_HOST} ^rto12\.ca$ [NC]
RewriteRule ^(.*)$ https://www.rto12.ca/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php?
RewriteRule ^index\.php?$ https://www.rto12.ca/ [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html?
RewriteRule ^index\.html?$ https://www.rto12.ca/ [R=301,L]

当您尝试访问此问题时,我的问题就出现了:rto12.ca ...浏览器会将您带到此处:“https://www.rto12.ca/https://rto12.ca/

这是造成这种情况的第一个条件/规则。任何建议将不胜感激。

1 个答案:

答案 0 :(得分:3)

这条规则:

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

...只会将请求重写为https://rto12.ca/REQUEST_URI,然后将其传递给下一个规则(您追加到请求结尾的下一个规则的输入将为{{1} }})。但是,要使其正常工作,您需要立即重定向:

https://rto12.ca/REQUEST_URI

有可能将所有规则组合到最多只有一个重定向,所以让我稍微讨论它,我会看到我能想到的,然后我会更新答案。但是,添加标志应该可以解决您的问题。

编辑:我认为这应该一气呵成:

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
相关问题