Rewrite a path to an argument

To simplify some deployments I’ve decided to migrate from Nginx to Caddy.

Given this Nginx conf:

rewrite ^/iiif/(.*)$ /fcgi-bin/iipsrv.fcgi?IIIF=$1;
location /fcgi-bin/iipsrv.fcgi {
                fastcgi_pass    iipsrv:9000;
                fastcgi_param   PATH_INFO $fastcgi_script_name;
                fastcgi_param   REQUEST_METHOD $request_method;
                fastcgi_param   QUERY_STRING $query_string;
                fastcgi_param   CONTENT_TYPE $content_type;
                fastcgi_param   CONTENT_LENGTH $content_length;
                fastcgi_param   SERVER_PROTOCOL $server_protocol;
                fastcgi_param   REQUEST_URI $request_uri;

I’ve made with this Caddy conf:

	handle /iip {
		reverse_proxy iipsrv:9000 {
			transport fastcgi

	handle_path /iiif/* {
		rewrite * /iip?IIIF={path}

What’s the error in that rewrite? The fastcgi proxy works fine:


handle and handle_path directives are mutually exclusive, so only the first matching one will run.

Please fill out the help topic template, as per the forum rules. We need to see your full config, logs, version, etc, to be able to give a precise suggestion of what to change to solve the problem.

Thanks, btw i solved in a completely different way: the service being proxied has now an option to understand the rewrite from the request.
So no need to do that, this is enough:

http://:80 {
	handle /iiif/* {
		reverse_proxy {
			transport fastcgi
	metrics /metrics
	encode zstd

Caddy for the win!

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.