我试图仅在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]
答案 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]