0

I have some legacy routes and I should redirect all of them to page 404. All of them have admin and user at the beginning. What are best practices to do this?

e.g. is there anyway to use regular expresion?

1

2 Answers 2

1

So Laravel can be a bit vague in terms of documentation about catch-all routes, you can use the following (untested) to catch any optional route below a given route and redirect back to a 404 page.

// Redirect all /admin routes
Route::get('admin/{any?}', function ($any = null) {
    return redirect('404');
})->where('any', '.*');

// Redirect all /user routes
Route::get('user/{any?}', function ($any = null) {
    return redirect('404');
})->where('any', '.*');

Personally I'd probably set up a rewrite to do this via a 301 permanent redirect before it even hits Laravel, but this should help you out in the meantime.

Sign up to request clarification or add additional context in comments.

Comments

1

It works for me:

Route::get('{legacy}', function($legacy){
    //
})->where('legacy', 'user.*|admin.*');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.