Always make a URL go to a specific file

1. Output of caddy version:

v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=

2. How I run Caddy:

Using CMD.

a. System environment:

Windows 10, no docker

b. Command:

caddy run --config "Caddyfile_Maintanence"

d. My complete Caddy config:

Paste your config here, replacing this text.
invite.[redacted].me {
	file_server
	root * "C:\Users\Web Servicing\Desktop\Maintanence"
	tls {
		dns cloudflare [redacted]
	}
}

jellyfin.[redacted].me {
	file_server
	root * "C:\Users\Web Servicing\Desktop\Maintanence"
	tls {
		dns cloudflare [redacted]
	}
}

legacy-jellyfin.[redacted].me {
	respond 200 {
	body	"#EXTM3U
#PLAYLIST:Currently down
#EXTINF:0,Currently down
https://jellyfin.[redacted].me/API/Maintanence.mp4"
	close
	}
}

request.[redacted].me {
	file_server
	root * "C:\Users\Web Servicing\Desktop\Maintanence"
	tls {
		dns cloudflare [redacted]
	}
}

api.[redacted].me {
	respond 200 {
	body	"#EXTM3U
#PLAYLIST:Currently down
#EXTINF:0,Currently down
https://jellyfin.[redacted].me/API/Maintanence.mp4"
	close
	}
	tls {
		dns cloudflare [redacted]
	}
}

3. The problem I’m having:

I’m trying to get Caddy to return a specific text file in a wildcard (jellyfin.[redacted].me/Items/*". If there’s anything on the *, or nothing at all, I want it to return the same text file.

5. What I already tried:

jellyfin.[redacted].me/Items/* {
	file_server
	root * "C:\Users\Web Servicing\Desktop\Maintanence\Items"
	tls {
		dns cloudflare [redacted]
	}
}

6. Links to relevant resources:

Using a path matcher in the site address is deprecated, and will be removed in a future version. Instead, use the handle directive to set up mutually exclusive routes.

Then, you can use the rewrite directive to rewrite the request path to the specific file you want, and serve it with file_server.

Change your jellyfin site to something like this:

jellyfin.example.com {
	tls {
		dns cloudflare {$API_KEY}
	}

	handle /Items/* {
		root * "C:\Users\Web Servicing\Desktop\Maintanence\Items"
		rewrite * /file.txt
		file_server
	}

	handle {
		reverse_proxy localhost:8096
	}
}

The handle with no matcher will catch any request that wasn’t otherwise matched by another handle directive’s matcher.

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