2013-06-05 49 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]