2013-06-05 31 views
4

当我到达url http://www.example.com/payments/add/2时,它应该自动重定向到https://www.example.com/payments/add/2
注意:我已经在我的服务器上安装了ssl。强制https在cakephp中的某些页面

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

该代码不起作用。请帮助

+0

你的代码引用了一个名为“支付”的控制器,而且您的网址都试图访问一个网址与控制器的apyments“。如果这不是一个错字,它可能是你问题的根源。 –

+0

sry它的错误错误..!现在我编辑了。 –

回答

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]