Ah, right. By design, the fastcgi transport uses the original request path (before any rewrites) for the REQUEST_URI env.
This is because we very often need to rewrite to index.php, which drops the remainder. The rewrite module and the proxy module are separate, and they don’t know about eachother. The problem is that we need to draw the line somewhere for the value of that env. We can’t really know whether a specific rewrite was intended to also apply to the path being sent or not. Caddy leans towards the “apps usually want the URL the client sent, untouched”.
Anyways I can offer you three options:
- You can override the env, which is an easy fix but is a funky workaround so it’s my least favorite:
php_fastcgi 127.0.0.1:9008 {
env REQUEST_URI /{re.api.2}
}
This uses the final matching group in your existing regexp to set the value.
-
Use a subdomain instead which doesn’t require changing the path at all, i.e.
env_01.api.example.com
. For testing locally, you can update your hosts file or run a local DNS server like CoreDNS to make whatever domain resolve to127.0.0.1
. -
Implement a change in your app that allows for a configurable base path in your router. Pretty sure Symfony allows for this. I write Laravel more often though. A quick Google seems to suggest you can use
framework.router.request_context.base_url
or the newerframework.router.default_uri
added in I think Symfony 5.1.