Z
Z
zlaravel2021-02-11 12:48:59
Laravel
zlaravel, 2021-02-11 12:48:59

How to fix Circular redirect on a page?

A circular redirect on a

Firefox page has determined that the server redirects the request to this address in such a way that it never completes.

This problem can occur when you disable or disable the acceptance of cookies.

<?php

namespace App\Http\Middleware;

use Closure;

class Mymiddleware
{
    public function handle($request, Closure $next)
    {
        if($request->route('page') != 'pages' ) {
            return redirect()->route('home');
        }

        return $next($request);
    }
}

<?php

Route::get('/', ['as'=>'home','uses'=>'Admin\[email protected]']);
Route::get('/about/{id}','[email protected]');
Route::get('/articles',['uses'=>'Admin\[email protected]','as'=>'articles']);
Route::get('/article/{id}',['uses'=>'Admin\[email protected]','as'=>'article']);
Route::get('/article/{page}',['middleware'=>'mymiddle:home','uses'=>'Admin\[email protected]','as'=>'article']);
Route::get('/pages', [PagesController::class, 'getIndex']);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Sarvarov, 2021-02-11
@zlaravel

You describe the task you are facing.
At the moment you have a really infinite redirect.
Try this by editing the redirection logic:

public function handle($request, Closure $next)
{
    if(! in_array($request->route()->getName(), ['home', 'pages'])) {
        return redirect()->route('home');
    }

    return $next($request);    
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question