强制https用于cakephp中的某些页面

时间:2013-06-05 14:22:56

标签: cakephp

当我到达网址http://www.example.com/payments/add/2时,它会自动重定向到https://www.example.com/payments/add/2 注意:我在服务器上安装了ssl。

if($this->params['action']=='add' && $this->params['controller']=='payments') 
    { $this->redirect('https://' . env('SERVER_NAME') . $this->here); }

该代码无效。请帮忙

1 个答案:

答案 0 :(得分:1)

试试这个

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

#redirect www.mydomain.com to mydomain.com (or any other subdomain)
RewriteCond %{HTTP_HOST} !^mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]

#force https for certain pages    
RewriteCond %{HTTPS} !=on
RewriteRule ^(page1\.php|page2\.php|page3\.php|page4\.php)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]