仅在yii网站的一个页面上强制https

时间:2015-09-07 16:09:37

标签: .htaccess yii

我试图仅在yii框架网站的一个页面上强制使用https,并让其余页面为http。强制https的页面是

https://www.mywebsite.com/index.php?r=user/profile

当我执行以下操作时,会强制https在网站上的所有页面上。

RewriteEngine On
# Go to https 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} ^/index.php?r=user/profile$ [NC]
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]

# Go to http 
RewriteCond %{SERVER_PORT} !80 
RewriteCond %{REQUEST_URI} !^/index.php?r=user/profile$ [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R,L]

1 个答案:

答案 0 :(得分:2)

查询字符串不是%{REQUEST_URI}变量的一部分,请尝试:

RewriteEngine On
# Go to https 
RewriteCond %{HTTPS} off
RewriteCond %{QUERY_STRING} ^r=user/profile$ [NC]
RewriteRule ^(index\.php)$ https://www.mywebsite.com/$1 [R,L]

# Go to http 
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_REFERER} !/index\.php\?r=user/profile
RewriteCond %{REQUEST_URI} !^/index\.php$ [OR]
RewriteCond %{QUERY_STRING} !^r=user/profile$ [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R,L]
相关问题