How to migrate legacy PHP web applications to Laravel

Developing new features on old sites is a daunting task. Sooner or later they will have to be modernized, rewritten from scratch, or ultimately shut down.

An interesting approach to refactoring old codebases is in-place migration. You don’t rewrite the whole project from scratch, you just tweak it a little and make it work alongside its modern version.

Our project consisted of a sales flow, and content directories serving as landing pages, written with SEO goals in mind.

Migrating legacy code to Laravel

We installed Laravel on a new directory, called it sales, and initially it was completely blank. To use the same old assets (images, CSS, and the like) we decided to keep the public folder, well, public to both the legacy code and the Laravel framework.

To handle the migration, we added a rule in Apache’s .htaccess to send a part of request to the new Laravel directory, with the front index file called sales-index.php

RewriteRule ^search sales-index.php [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]