htaccess重写规则在https重定向上失败

时间:2014-01-16 00:13:57

标签: apache .htaccess mod-rewrite redirect

我的htaccess看起来像这样

RewriteEngine On
RewriteCond %{HTTP_HOST} !^localhost$
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^login/?(.*)$ login.php$1 [L]
RewriteRule ^register/?(.*)$ register.php$1 [L]

我想重定向我的网页登录并重定向到https,所以我添加了下面的代码

RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/(login|register)/?$
RewriteRule .*$ http://%{HTTP_HOST}%{REQUEST_URI} [L]

所以当我输入 http ://www.xyz.com/login/时,它会重定向到 https ://www.xyz.com/login/所有内容都是很好,当我决定将页面重定向到http,而不是登录或注册,我写了

RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/(login|register)/?$
RewriteRule .*$ http://%{HTTP_HOST}%{REQUEST_URI} [L]

之后我再次测试了网址 http ://www.xyz.com/login/,并将其重定向到 https ://www.xyz.com /login.php

有任何想法将 http ://www.xyz.com/login/重定向到 https ://www.xyz.com/login/并在该页面上当我点击链接 https ://www.xyz.com/news/1/重定向到 http ://www.xyz.com/news/1/ < / p>

1 个答案:

答案 0 :(得分:0)

尝试在RewriteEngine On行下面添加此内容:

RewriteCond %{HTTPS} off
RewriteRule ^(login|register)(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

RewriteCond %{HTTPS} on
RewriteRule !^(login|register) http://%{HTTP_HOST}%{REQUEST_URI} [L,R]

看起来你的规则也错了,这两个规则是相同的。

相关问题