Reputation: 41
I am trying to force https only on one page of a yii framework website, and let the rest of the pages be http. The page that would be forced https is
https://www.mywebsite.com/index.php?r=user/profile
When I do the following, it forces https on all the pages on the website.
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]
Upvotes: 2
Views: 217
Reputation: 143906
The query string isn't part of the %{REQUEST_URI}
variable, try:
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]
Upvotes: 2