framework: Redirect Loop - ERR_TOO_MANY_REDIRECTS
- Laravel Version: 5.8.4
- PHP Version: 7.1.26
Description:
Website is in the Redirect Loop when I am using function with redirect()->back(); from other site.
Steps To Reproduce:
routes\web.php
Route::get('/test', 'Auth\AuthController@goBack');
Auth\AuthController.php
public function goBack()
{
return redirect()->back();
}
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 23 (12 by maintainers)
We’ve merged the PR which fixes this.
@driesvints I’m able to confirm this issue. Here’s a shell script to setup a recreation:
Then run each of these:
I actually experienced this same issue in my application since upgrading and I didn’t remember it behaving like that.
Okay I’ll re-open this as quite a few people are experiencing issues with this it seems. Thanks for verifying.
I understand that if I go to the URL directly, there is no previous page.
However, if I was first on a different page within the domain (home page) and I changed the URL in the browser directly, it worked before and there was no redirect loop.
It’s different when I use an older version of Laravel 5.7.28 and when I use Laravel 5.8.4. I get different behavior. Why? This is a problem. Laravel’s functionality has changed.
Maybe it worked through a session that had a different value in Laravel 5.7. But now there is only a new url in the session for the previous page.
For example, I have a GET function to switch the application language. The function will change the language and return to the previous page even if I changed the url directly. Now I’ll get a loop for the URL www.domain.com/lang/en.
I corrected my method as follows:
return (request()->header('referer')) ? redirect()->back() : redirect()->home();
My suggestion:
If there is no previous page, it returns an error page and not redirector loop.
Your opinion?