Force https for specific pages in cakephp

When I get to the URL http://www.example.com/payments/add/2 , it should automatically redirect to https://www.example.com/payments/add/2 .
Note. I installed ssl on my server.

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

This code does not work. Please, help

+4
source share
1 answer

try it

 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] 
+1
source

Source: https://habr.com/ru/post/1484659/


All Articles