CakePHP $this->redirect($this->Auth->redirectUrl()); Duplicates BaseURL in Redirect

2.5k views Asked by At

In CakePHP v2.3.8, after a user logs in, I want to send them to the page they were trying to access. CakePHP is running out of a subdirectory (baseurl in the example below):

$this->redirect($this->Auth->redirectUrl()); sends me to:

http://example.com/baseurl/baseurl/controller/action

It should send me to:

http://example.com/baseurl/controller/action

Is anyone else getting a duplicated base url in their redirects? Does anybody know how to fix it? This is my first time using CakePHP, so please let me know if I'm not asking the right question or providing the needed information. Thanks!

Note: I see a similar addressed as a bug in RC version 2.4. However, I'm running v2.3.8, so I don't think this is the exact issue. The fix in this commit looks identical to my code in v2.3.8.

1

There are 1 answers

0
Chris Voth On BEST ANSWER

The issue is with line 680 of lib/Cake/Controller/Component/AuthComponent.php

return Router::url($redir);

Changing it to the following (which was an update in 2.3.9) fixes it:

return Router::url($redir + array('base' => false));

As does changing it to this (which is an update in 2.4):

return Router::normalize($redir, false);

See commit message here: https://github.com/cakephp/cakephp/commit/8133f72

Obviously editing the CakePHP core files isn't a good idea, so I upgraded to 2.3.9 to fix the issue.