Monday, July 1, 2013

Re: 301 infinite redirect

Hi AD,

thanks for the help. I'm still trying to solve this problem.

If I use a redirect 301 from /testnews/test to testredirect/test with $this->redirect(array('controller' => 'testredirect', 'action' => 'test'), 301);

I get this headers:

GET /testnews/test HTTP/1.1
Accept: */*
Accept-Encoding: gzip
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Language: en-us,en;q=0.5
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
Connection: Keep-Alive
SERVER RESPONSE: 301 Moved Permanently
Date: Mon, 01 Jul 2013 16:16:18 GMT
Server: Apache
X-Powered-By: PHP/5.3.2-1ubuntu4.17
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 20
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset="UTF-8"
GET /testredirect/test HTTP/1.1
Accept: */*
Accept-Encoding: gzip
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Language: en-us,en;q=0.5
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
Connection: Keep-Alive
SERVER RESPONSE: 301 Moved Permanently
Date: Mon, 01 Jul 2013 16:16:18 GMT
Server: Apache
Vary: Accept-Encoding
Content-Encoding: gzip
X-Powered-By: PHP/5.3.2-1ubuntu4.17
Age: 0
Content-Length: 20
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Content-Type: text/html; charset="UTF-8"

And so on...

So, logging I can not find the problem. 

2013-07-01 18:16:18 Error: /testnews/test
2013-07-01 18:16:18 Error: 301
2013-07-01 18:16:18 Error: Array
(
    [controller] => testredirect
    [action] => test
)

2013-07-01 18:16:18 Error: TestnewsController::redirect() - APP/Controller/TestnewsController.php, line 29
TestnewsController::test() - APP/Controller/TestnewsController.php, line 13
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE/Cake/Controller/Controller.php, line 486
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 187
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 162
[main] - APP/webroot/index.php, line 96

The only one thing I detected is that a log message placed inside AppController::beforeFilter() is never written to the log for /testredirect/test (the destination page, that starts the loop).

With 302 redirect works well, this behaviour only happens with 301. Could it be a bug?

Thanks a lot for your time!

Albert

El dilluns 1 de juliol de 2013 15:09:16 UTC+2, AD7six va escriure:
The easiest way to debug redirect problems is to put:

public function redirect($url) {
    debug($url);
    debug(Debugger::trace());
    die;
}

OR

public function redirect($url) {
    $this->log($this->here);
    $this->log($url);
    $this->log(Debugger::trace());
    parent::redirect($url);
}

Or similar, In your app controller, and determine why/how/what causes the problem url to redirect to itself.

AD

On Monday, 1 July 2013 14:46:05 UTC+2, floydbrush wrote:
Hi,

I need to made a 301 redirect from one url to another. So i tried to use:

$this->redirect($newUrl, 301);

The redirect works first time, but is infinite and throws ERR_TOO_MANY_REDIRECTS, so Search Engines bots can't index the new url.

I checked the headers and I don't understand why the hell not stops once the redirect is made after first 301. Example: http://urivalet.com/?http://www.pasteleria.com/noticias/view/el-chocolate-ya-se-consumia-en-el-1150-a-c/179#Report

I started a "clean" cakephp app  for try if there's a problem with my current app, and the behaviour is the same.

If I use redirect 302 instead of 301, the redirect works fine (or 303, 307, 404...). Only causes a loop with 301.

I have no idea what is happening. Any tips?

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: