# Reroute http to https

**URL:** <https://discourse.cakephp.org/t/reroute-http-to-https/3483>\
**Category:** Uncategorized\
**Created:** [November 12, 2017, 10:47pm UTC](https://discourse.cakephp.org/t/reroute-http-to-https/3483 "2017-11-12T22:47:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [November 12, 2017, 10:47pm UTC](https://discourse.cakephp.org/t/reroute-http-to-https/3483/1 "2017-11-12T22:47:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [November 13, 2017, 11:43am UTC](https://discourse.cakephp.org/t/reroute-http-to-https/3483/2 "2017-11-13T11:43:39Z")

</div>

You should try the .htaccess file

---

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [November 14, 2017, 12:16pm UTC](https://discourse.cakephp.org/t/reroute-http-to-https/3483/3 "2017-11-14T12:16:59Z")

</div>

isnt there a cakephp3 solution?

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [November 14, 2017, 1:54pm UTC](https://discourse.cakephp.org/t/reroute-http-to-https/3483/4 "2017-11-14T13:54:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tobse](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/tobse/32/236_2.png) [@Tobse](https://discourse.cakephp.org/u/Tobse)\
**Post date:** [November 16, 2017, 1:03pm UTC](https://discourse.cakephp.org/t/reroute-http-to-https/3483/5 "2017-11-16T13:03:48Z")

</div>

You can do it via the Security-Component.

[https://book.cakephp.org/3.0/en/controllers/components/security.html#restrict-actions-to-ssl](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());
 }
```

---

<div class="post-metadata">

**Author:** ![gildonei](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/gildonei/32/844_2.png) [@gildonei](https://discourse.cakephp.org/u/gildonei)\
**Post date:** [November 17, 2017, 7:30pm UTC](https://discourse.cakephp.org/t/reroute-http-to-https/3483/6 "2017-11-17T19:30:40Z")

</div>

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>
```

---

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [November 18, 2017, 2:44am UTC](https://discourse.cakephp.org/t/reroute-http-to-https/3483/7 "2017-11-18T02:44:23Z")

</div>

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](https://www.namecheap.com/support/knowledgebase/article.aspx/9410/29/how-to-set-up-rules-and-redirects-in-htaccess)

---

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [November 18, 2017, 11:13pm UTC](https://discourse.cakephp.org/t/reroute-http-to-https/3483/8 "2017-11-18T23:13:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danilo1945](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/danilo1945/32/1340_2.png) [@danilo1945](https://discourse.cakephp.org/u/danilo1945)\
**Post date:** [February 15, 2019, 8:40pm UTC](https://discourse.cakephp.org/t/reroute-http-to-https/3483/9 "2019-02-15T20:40:06Z")

</div>

Este codigo me sirvio en el .htaccess ya que redirecciona todas las rutas del proyecto.  
en el lugar de [www.midominio.com](http://www.midominio.com) va tu domino.

 RewriteEngine on RewriteCond %{SERVER\_PORT} 80 RewriteRule ^(.\*)$ https://www.midominio.com/$1 [R,L] RewriteRule ^$ webroot/ [L] RewriteRule (.\*) webroot/$1 [L]
