htaccess if语句https重定向一页

时间:2014-03-20 21:15:09

标签: apache .htaccess redirect https

我在客户的安全页面和相对导航方面犯了一个大错误,现在谷歌开始索引网站显示https的结果,而不是http版本,因为它“打破”了网站。

我想301将除1之外的所有页面重定向到htaccess中的非https版本。

我正在尝试将除/(语言变量)/form.html之外的每个页面重定向回http://版本,但我正在运行apache 2.2.26。我看到类似于我想要的东西,但我没有运行Apache 2.4,所以我得到500错误。

 RewriteEngine on
<If "%{HTTP_HOST} == 'www.canpujolet.com/^([a-z]{2})/form.html$'">
RewriteCond %{HTTPS}  off
RewriteRule  ^([a-z]{2})/form.html$  https://www.canpujolet.com/$1/form.html  [R=301,L,QSA]
</If>

<Else "%{HTTP_HOST} !== 'www.canpujolet.com/^([a-z]{2})/form.html$'">
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]
</Else>

非常感谢任何帮助和建议。

1 个答案:

答案 0 :(得分:1)

您可以使用:

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} \s/[a-z]{2}/form\.html
RewriteRule ^[a-z]{2}/form\.html$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]

RewriteCond %{HTTPS} on
RewriteRule !^[a-z]{2}/form\.html$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]