Configure a route to point to a php url like "/in.php"
I have a server that receives data from a popular service and for which the initial route was just a plain php file myserver.com/in.php. I moved the entire app to a Lumen app and now I am forced to setup either a file in public/in.php or create a route /in.php. I want to create a route to /in.php but I am struggling to do with in Nginx. The only thing I was able to do was a rewrite that creates a permanent 301 and changes the route from /in.php to a route in lumen /in. However I don't know how the service handles redirects and I am still trying to find a way to declare in lumen a route that ends in .php.
Anyone has an idea how to achieve this?
Btw, I am currently using homestead with the default Nginx configuration.
Certainly you could massage nginx server config a little and have it serve any PHP file in the /public directory, first, if it exists, before invoking the default 'index.php' which then bootstraps Lumen. Let me know if that's what you think you need, I could probably help with that, but
You can define any routes you want in the router. So, if you want, why not, in routes/web.php simply create the route:
$router->get('in.php', function () {
// invoke a controller method
// or whatever you want...
return 'in.php';
});
@burlresearch i want to implement option #2. I've tried it like that already and it does not work. It tries to find the file in public and if the file is not there it fails.
For option #2 have you tried without the physical PHP file in the public dir? I believe option #2 will only work if /public/in.php does not exist. Latter assumes you are using an unmodified Lumen .htaccess file.
In situations where I have a legacy url I'd prefer to migrate it into Lumen.
I don't have the "in.php" file in the public folder, just the "index.php". I have configured the route like $router->post("/in.php", "IncomingController@in").
Nginx looks like this for locations which matters. I don't use rewrites in it right now, it's just the default homestead generated conf.
I was using Laravel Valet on my Mac when I tried that $router->get('in.php',... and it worked OK, but that isn't using the same NGINX config as above (I assume).
Later I tried it on my native linux box, and it did not work - and that's with NGINX configured as yours above.
But, if you simply move the 'in.php' to your public/ folder, it will be run as expected and rendered as a normal PHP page (though obviously not bootstrapping Laravel/Lumen).