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();
}
  1. http://localhost/public
  2. http://localhost/public/go => Loop

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 23 (12 by maintainers)

Most upvoted comments

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:

#!/bin/sh

mkdir redirect-tests
cd redirect-tests

composer create-project --prefer-dist laravel/laravel=5.7.28 laravel57
echo "Route::get('/back', function () {
    return back();
});" >> laravel57/routes/web.php

composer create-project --prefer-dist laravel/laravel=5.8.3 laravel58
echo "Route::get('/back', function () {
    return back();
});" >> laravel58/routes/web.php

Then run each of these:

echo "Click here to see it's OK with 5.7: http://127.0.0.1:5700/back" && php redirect-tests/laravel57/artisan serve --port 5700 --quiet
echo "Click here to see the issue with 5.8: http://127.0.0.1:5800/back" && php redirect-tests/laravel58/artisan serve --port 5800 --quiet

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?