The new Route::redirect
introduced in Laravel 5.5 is practical, but does it allow {any}
wildcard?
Here is what I used to do in Laravel 5.4
Route::get('slug', function () {
return redirect('new-slug', 301);
});
In Laravel 5.5, I can do the following:
Route::redirect('slug', url('new-slug'), 301);
Which allows route caching by getting rid of the closure.
So far so good, but what if I want to use a wildcard? In Laravel 5.4, I could do:
Route::get('slug/{any}', function ($any) {
return redirect('new-slug/'.$any, 301);
});
Of course, I can still use this in Laravel 5.5, but my point is to be able to cache my route files.
Does the new Route::redirect
allow the use of a wildcard, or is my only option to use a controller?
EDIT: What I am attempting to do is something like this:
Route::redirect('slug/{any}', url('new-slug/'.$any), 301);
Which of course doesn't work because I don't know where to reference the $any
variable.