Note that once you have added an additional segment to the `x-forwarded-for` value, then the next request will have that segment in its own `x-forwarded-for` value. i.e. `x-forwarded-for` contains the full URL that was requested by the client
For example. Let's say that you start with an `x-forwarded-for` of `https://example.com/foo/bar/url-demo/php` and you respond with the new item's URL of `https://example.com/foo/bar/url-demo/php/42`. When the client requests the new URL, the `x-forwarded-for` will contain the `https://example.com/foo/bar/url-demo/php/42` which is not the original `base_url`.
You can look in `params['__ow_path']` to find this addition and so remove it from `x-forwarded-for` to get back to your original `base_url`.