Caddy with Symfony put under a symlinked subdirectory

By design, REQUEST_URI is the original URI from the request, unmodified by rewrites.

The problem is that you have two rewrites happening here. The one from uri strip_prefix, then the one from the built-in try_files in php_fastcgi, which rewrites it to /index.php.

One thing you could do is capture the {path} at the point right after the prefix is stripped and then overwrite REQUEST_URI with that value.

	handle_path /orbitale_cms/* {
		vars subpath_uri {uri}
		root * /var/www/demo.orbitale.io/repos/demos.orbitale_cms/public
		php_fastcgi unix//run/php/php8.1-fpm.sock {
			env REQUEST_URI {vars.subpath_uri}
		}
	}

Here’s we’re using handle_path instead of handle + uri strip_prefix because it saves a line, plus ensures the order of operations is correct (because otherwise the directive order would mess with it).

Keep in mind that if you do this, then your PHP app will have no way of knowing the original URI, so it won’t know how to perform redirects or how to construct paths that reach the same handle block. You’ll need to configure your backend app somehow to be aware of a base URL.

The explanation from this article applies here as well: