Y
Y
Yuri Smith2017-10-12 17:04:26
Laravel
Yuri Smith, 2017-10-12 17:04:26

How to remove redirect in Laravel on 404?

Hello. You need to remove the redirect on the 404 page. Any page can open as site.ru/page and the redicert will be on site.ru/page/ This is implemented in the controller via $this->middleware('redirect'); but it is necessary that 404 opens as it is written, without a redirect - site.ru/page123 opens like that, and not as it is now site.ru/page123/ Middleware code:

public function handle($request, Closure $next)
{ 
    if (!preg_match('/.+\/$/', $request->getRequestUri()))
    { 
        return Redirect::to( preg_replace("/\s{2,}/",'/', $request->getRequestUri() . "/" ), 301);
    }
    return $next($request);
}

All this works well, but on the 404 page it needs to be removed. If there is no data, then we transfer to 404, I do it like this:
if (!$data) {
     App::abort(404);
 }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mokhirjon Naimov, 2017-10-12
@zvermafia

Well, check the 404 page on the same middleware.
Well, like:

if ($page !== 404) {
    // редирект
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question