Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DarioCorno's avatar

Redirecting old URLs to new Routes

Hi everyone, I'm migrating an old plain php website to Laravel, everything works fine except one small thing. Evey time I port an old website to Laravel I'm facing the same problem : keeping the old urls working cause the customer already shared on the net, social and so on, and rightly he doesn't want to loose the seo work he has done.

Right now I've created an array of old urls -> new urls and create the routes with redirects in a simpel foreach loop.

Is there a "best practice" to handle this situation? Changing the .htaccess? (even if I prefer the customer to be able to edit the redirects array) Some kind of library?

And finally, is there a simpe way to allow some urls like http://ww.website.com/folder/something.php to pass through the routing untouched (running the something.php) and at the same time redirecting http://www.website.com/folder/anothersomething.php to a Laravel route?

0 likes
10 replies
Rustproof's avatar

I'm also migrating a site to laravel and would like the previous pages to redirect to the new pages.... There is just one thing.

What if I'm already redirecting my public folder through htaccess?

RewriteEngine on RewriteCond %{REQUEST_URI} !^public RewriteRule ^(.*)$ public/$1 [L]

DarioCorno's avatar

I actually ended up creating a controller that manages an old-route -> new-route relationship and generates the routes with the full path. It was actually quite an easy job cause I used the old sitemap to parse old routes and the new ones have similar names,

Rustproof's avatar

Thanks for the suggestion. I added another htaccess within my public folder, then added my redirects there.

Snapey's avatar

@Rustproof

how do you have two htaccess files in the same folder?

if you don't, because actually one is in the main laravel folder then you have a serious vulnerability in your setup.. one that could allow someone list the contents of your .env file

Rustproof's avatar

Different folders.

I have a parent .htaccess redirect to the "public" folder that Laravel creates. Then, I have a .htaccess within that "public" folder to handle the redirects.

Rustproof's avatar

Is there a proper way to set up my Laravel installation, rather than using .htaccess redirects?

I recently installed an SSL certificate and I'd typically use .htaccess to force HTTPS, but there are too many redirects.

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
fastsol's avatar

This worked slick without any htaccess hacks. This is what I did to handle GET parameters that I needed to change around Route::redirect('quotes.php', 'quote/'.request()['quote-id'] ?? ''.'/'.request()['c'] ?? '');

Please or to participate in this conversation.