Reputation: 360
I am trying to make Laravel work with a non-laravel script.
I need Laravel to handle only routes that are set in the web.php file, and allow anything else that's not defined to be handled by my non-laravel-PHP's legacy_index.php.
This is the folder setup that I have in my public. legacy_index.php is the one that belongs to my non-laravel-php script. The legacy_index.php script has a URL parsing algorithm in it. I want Laravel to allow me to use the legacy_index.php if the path I am trying to access is not declared in the routes, but without showing the legacy_index.php file in the link.
As an example: Laravel would process these routes:
But would ignore these routes:
And would let my legacy_index.php to handle the routing for these two.
I have tried by editing the .htaccess file, trying to redirect to these links from the routes, but nothing worked.
Did anyone do this before and has any tips/pointers? I am developing on Windows, using Laravel 8.42.
Upvotes: 0
Views: 318
Reputation: 3657
It looks like your routes are neatly identified by the a simple rule that if they begin with "/api" then you want Laravel's index.php to handle it but if it doesn't then you want legacy_index.php to handle it. Therefore adding another conditional rewrite rule to the .htaccess might be 1 method.
...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/api/(.+)
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index_legacy.php [L]
Upvotes: 2
Reputation: 330
Migrating Legacy Web Applications to Laravel might be useful to you.
See Step Three: Hand Off to Legacy Framework
Upvotes: 1