Jeferson Assis
Jeferson Assis

Reputation: 125

Define Router to use SSL by default

I have a AWS ELB with default port 443 (SSL) and accessing the EC2 using port 80.

If I use $this->Url->build() or Router::url() always return url without https.

Exists a possibility to set Router::url() to use SSL by default?

Upvotes: 1

Views: 1249

Answers (1)

Alex Stallen
Alex Stallen

Reputation: 2252

Use the following to generate https urls:

router::url([
    'controller' => 'yourController', 
    'action' => 'yourAction',
    '_full' => true,
    '_ssl' => true
]);

Reference http://api.cakephp.org/3.0/class-Cake.Routing.Router.html#_url

to set the default to ssl I think you will need to override the cake core and change the default _ssl setting to true (vendor\cakephp\cakephp\src\routing\Router.php) but I would not go that far

Upvotes: 2

Related Questions