CakePHP的 - 选择SSL [英] CakePHP - Selective SSL
问题描述
如何强制HTTPS的网站,如某些部分一个登录页面或注册页面,并使用HTTP的网站的其他部分?
How do I force HTTPS for certain parts of a site, e.g. a login page or register page, and use HTTP for the rest of the site?
推荐答案
我最喜欢的转换到https强制方法是将本作中,你的PHP脚本的第一件事。它的工作原理中的Joomla,并可能在CakePHP中很好地工作。
My favorite convert to https forcing method is to put this as the first thing in your php script. It works in Joomla, and may very well work in CakePHP.
if( $_SERVER['SERVER_PORT'] == 80) {
header('Location:https://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/'.basename($_SERVER['PHP_SELF']));
die();
}
这个片段将迫使任何网页您正在查看HTTPS。如果要隔离certian页面,只是把基于信息的某些条件中的$ _ SERVER ['PHP_SELF']变量。
This snippet will force https on whatever page you are viewing. If you want to isolate certian pages, just put some conditions based on the information in the "$_SERVER['PHP_SELF']" variable.
否则,修改.htaccess文件,假设你的主机允许您访问的:
Otherwise, modify the .htaccess file, assuming your host allows you access to this:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} somefolder
RewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]
这篇关于CakePHP的 - 选择SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!