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

vedoj's avatar
Level 1

Dealing with old legacy links after rewriting old PHP website into Laravel

The old website has links like http://example.com/index.php?article=3402

What is the best strategy to deal with them after the rewrite? I want them to work and redirect to the new links that look like http://example2.com/russia-invaded-ukraine-two-hours-ago

I was thinking about saving the whole index.php?article=3402 part as slug_old in the articles table.

And then checking not only the slug column but also the slug_old column if the parameter in the url corresponds to one of them.

Then depending on the result I am not sure, again, what to do next.

Should I:

  1. somehow add the code 301 (moved permanently) to the header of the response? How to do that in the controller? When returning the view at the end or before?
  2. or should I redirect first to the new link with the code 301 and then proceed as usual?

Or is this strategy not optimal and you would suggest something better?

Thank you in advance.

0 likes
1 reply
bait-dept's avatar

@vedoj You could have a redirects table that maps the old article ids to the new ones.

Dependent on your setup (LAMP or LEMP) you could setup the old entry at /index.php to point to a specific route and on the controller responsible for that route then have a logic that handles verifying the received article Id and perform a 301 redirect.

Please or to participate in this conversation.