I’m rewriting an website in laravel, and for the sake of the SEO, I have to create some routes that will do a 301 redirect in case the visitor get to access the old style links of the website:
Using Laravel 5.4 + PHP 7.0
For example:
Old links: www.website.com/category.php?category={id}
will redirect to:
New Link: www.website.com/category/{category-name}
But when I create a route like this on laravel, it doesn’t work:
Route::get('/category.php?category={id}', function ($id) {
// Old route style, search new route and do the redirect.
});
If I remove the “?” it kinda works, but then it won’t target my old links, cause there’s no “?” in the url.
Is this supported on laravel ?
If it isn’t, what would be a good way to achieve this?
3
Answers
Htaccess is your friend in this case. You can create a 301 redirect from your old category base to the new like so:
What is your controller?
You can get your controller resource
And all those route will be added to your route:list with no pain.
make your route like this and pass the category id. for example I have taken that 10.
and take id from the request object.