Reroute http to https


#1

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.

Thanks
Andrew


#2

You should try the .htaccess file


#3

isnt there a cakephp3 solution?


#4

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


#5

You can do it via the Security-Component.

https://book.cakephp.org/3.0/en/controllers/components/security.html#restrict-actions-to-ssl

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

Example:
In your AppController.php

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

 public function beforeFilter(Event $event)
 {
 $this->Security->requireSecure();
  }

public function forceSSL()
{
return $this->redirect('https:/my-domain.com' . $this->request->getRequestTarget());
 }

#6

With .htaccess you can use the following

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.fomedeofertas.com.br/$1 [R,L] 
</IfModule>

#7

with .htaccess where is this when using cpanel ?

is this it?
https://www.namecheap.com/support/knowledgebase/article.aspx/9410/29/how-to-set-up-rules-and-redirects-in-htaccess


#8

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 ^(.*)$ https://crm.xxxxx.au/$1 [R,L] 
   </IfModule>

php – BEGIN cPanel-generated handler, do not edit

This domain inherits the “PHP” package.

php – END cPanel-generated handler, do not edit