I’m deploying a laminas app in a subfolder under my domain (https://renanliberato.com.br/myapp), and I don’t know exactly how to deal with this “/myapp” prefix on my app.
Currently, I’m adding this base path into all my routes configurations, like this:
However, it seems wrong to add this information directly in the routes. I’d expect to have a way to setup it in local.php or global.php, so that when I’d want to deploy it on a subdomain or a separate domain, I’d not need to rewrite all the routes.
For view paths (for static assets), I could find how to do it using ‘view_manager’ > ‘base_path’ in the config and ‘$this->basePath()’ in the templates, but nothing for routes.
Do you guys know If it is possible via laminas config, or via .htaccess, or if I should not care at all about it (hehe)?
Everything is already there. Please check the comment in the .htaccess file of the skeleton application:
Yeah, I noticed that it helps in the index.php script resolution. However, I still need to include the subdirectory in my routes.
Please remember, because someone writes something here, it is not the official or only solution.
Sure. I should not have marked it as a solution on first hand. Not because @williamgall specifically posted it, but because it was the first and only one in a short timespan.
Using global constants was the solution in version 1 of the Zend Framework but now it is no longer recommended.
I’m not sure if another solution will fit what I want (or if I should expect it from the framework, anyway)… The simplest case that I’m referring too is:
My app is hosted on a “myapp” subdirectory. So, I’d like to, when declaring a route ‘/about’, the user would be able to access it by going to “https://domain.com/myapp/about”. However, it does not seem to work… I must implement my route like ‘/myapp/about’ otherwise I get a 404 error.
Hey, I could not find exactly what is making my basePath be empty (probably some deploy specifcness), so I extended the RequestFactory and set both basePath and baseUrl manually (via a local.php config, so at least not hard coded).
That’s enough for now, as both routes and assets resolutions are working.
I’ll try to understand better why the basePath resolution is resolving to empty later on.