.htaccess 仅在yii网站的一个页面上强制使用https

.htaccess 仅在yii网站的一个页面上强制使用https,.htaccess,yii,.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/pr

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

查询字符串不是
%{REQUEST\u 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]

出于好奇:你到底为什么要阻止页面使用SSL/TLS?我正在运行一个闪亮的应用程序,它监听端口3838。我不知道如何让它在SSL安全开启时监听。我还没有找到解决办法,因为我对港口运输等不太熟悉。嗨,乔恩。这实际上非常有效。非常感谢。我现在唯一的问题是,css不会为这一页加载。甚至当我将css文件的url更改为https时,我相信这是考虑到页面的其余部分是在http中加载的,并在sammer中请求css文件。有什么简单的解决方法吗?@MichaelDowers尝试向http重定向添加一个附加条件(参见上面的编辑),谢谢Jon。现在一切都正常加载。但是,通过http收集的gif和png文件的内容是混合的。(不安全图像)我是否可以在htaccess中放置任何东西来通过https收集这些图像?它们正在导航栏中使用。