0
votes

A client asks me to redirect an old URL to a new one. Only, the URL it gives me contains a parameter and it is impossible to do a .htaccess redirect with that. I tested and I did not succeed.

I would like to redirect with the Laravel route system.

I tried this :

Route::get('places.php?p=1740', function () {
   return redirect('new/url');
});

But I have the same problem. I have a 404 error that the page does not exist. I tried without the parameter and it works.

I also tried this:

Route::get('places.php/{p}', function ($p = '1740') {
    return redirect('new/url');
});

But it does not work either.

I just need a solution that works to redirect his url with a parameter to a new one.

Thank you !

2
If your webserver is setup properly, you shouldn't need .php in your routes; Route::get("/places/{p}", ...) should be fine. Navigating to http://your-app/places/1740 should redirect you to http://your-app/new/urlTim Lewis

2 Answers

0
votes

In laravel routing system you don't need to specify .php extension, use like below:

Route::get('places/{p}', function ($p = '1740') {
    return redirect('new/url');
});
0
votes

If I understand this correctly, you have an old url from a version of the website not built in Laravel and this url is probably indexed by search engines and users are hitting a 404 when visiting this url. And your goal is to setup up a 301 redirect from https://example.com/places.php?p=1740 to https://example.com/new/url.

If this is the case you should be able to achieve this by adding this line to /public/.htaccess:

Redirect 301 /places.php?p=1740 /new/url

Or you might be able to do this via the routes file:

Route::redirect('/places.php?p=1740', '/new/url', 301);