Reroute http to https


Hi, I have my website on https which was on http. How do I redirect/reroute users to https ? I was quite clear where I need to do this in cakephp3. I see some methods using cakephp2 but this is using older framework.


CAKE 2.3.5 Moved to SSL now users will not authenticate

You should try the .htaccess file


isnt there a cakephp3 solution?


Using .htaccess is the optimal solution. You can do it via CakePHP but that is less than the best.


You can do it via the Security-Component.

If your action is called over http instead of https, the request is “blackholed”.

In your AppController.php

public function initialize()
$this->loadComponent('Security', ['blackHoleCallback' => 'forceSSL']);

 public function beforeFilter(Event $event)

public function forceSSL()
return $this->redirect('https:/' . $this->request->getRequestTarget());


With .htaccess you can use the following

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$$1 [R,L] 


with .htaccess where is this when using cpanel ?

is this it?


This code currently exists in htaccess so what do i do now as tbhis didnt work. It doesnt redirect http to https and i edited out the actual domain?

  <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteRule    ^$    webroot/    [L]
     RewriteRule    (.*) webroot/$1    [L]

    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$$1 [R,L] 

php – BEGIN cPanel-generated handler, do not edit

This domain inherits the “PHP” package.

php – END cPanel-generated handler, do not edit


Este codigo me sirvio en el .htaccess ya que redirecciona todas las rutas del proyecto.
en el lugar de va tu domino.

RewriteEngine on RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$$1 [R,L] RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L]