I customised the base path for my site like this:
Router::scope('/', function (RouteBuilder $routes) {
//$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
//My custom base path
$routes->connect('/', ['controller' => 'Posts', 'action' => 'index', 'home']);
//Connect the rest of PagesController URLs
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
//I don't quite understand what this line does
$routes->fallbacks(DashedRoute::class);
});
Then the URLs are correct when I redirect inside the controllers like this:
return $this->redirect(['controller' => 'Posts', 'action' => 'view', $data['post_id']]);
//output:
// localhost/jayblog/posts/view/2
But for external links and WWWROOT
, it returns the wrong ones:
<li><a href="https://www.example.com" target="_blank" title="Twitter">LINK</a></li>
//output is wrong:
// localhost/jayblog/https://www.example.com
<?= $this->Html->image(WWW_ROOT.DS.'files'.DS.$photos[$i]->file_name); ?>
//output:
// jayblogD:\path\to\file.PNG
Anyone please suggest me how to fix the problem. Thank you!