Tuesday, January 25, 2022

[FIXED] Define Router to use SSL by default

Issue

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?


Solution

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



Answered By - Alex Stallen

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.