-4

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.

Chris Voth
  • 853
  • 5
  • 13
  • 22
  • We’re going to need to see some code before we could even *begin* to guess what’s going on. – Martin Bean Aug 22 '13 at 15:39
  • 1
    Apparently this issue is the same/similar as a documented bug in an RC version: https://cakephp.lighthouseapp.com/projects/42648/tickets/3938-this-redirectthis-auth-redirecturl-broken – Chris Voth Aug 22 '13 at 15:42
  • "is anyone else having this issue?" is not a question appropriate for Stack overflow – AD7six Aug 22 '13 at 15:45
  • @AD7six Unfortunately, the documented bug is in an RC version that I'm not running (2.4). I'm running the sable version of 2.3.8. – Chris Voth Aug 22 '13 at 15:50
  • which means it's not the problem (in which case there's no relevant information at all) or it is a problem but isn't thought to apply before 2.4 - either way - you should edit the question with **more information**. You've just edited the question and still don't mention you're installed in a subdirectory. – AD7six Aug 22 '13 at 15:53
  • @MartinBean I would be happy to provide code, however I don't know what code you would want to see... Do you want to see the controller code? Do you want to see the config files? – Chris Voth Aug 22 '13 at 15:55
  • Similar issue in cakephp v2.6 but I resolved it. Seem my answer at http://stackoverflow.com/questions/26363825/cakephp-bad-auth-redirection/27813239#27813239 – Faiyaz Alam Jan 07 '15 at 06:21

1 Answers1

2

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.

Chris Voth
  • 853
  • 5
  • 13
  • 22