Simple Rewrite returning 404

I have a Dockerised container for Caddy that mounts some static assets, for some reason my rewrite attempts 404:

log stdout
errors stdout

rewrite {
	r [a-z]+\.css

	to /assets/styles/

rewrite {
	r [a-z]+\.js

	to /assets/scripts/

The docker-compose file is like so:

    image: demo/caddy
     - 8585:8585
     - ./assets:/assets:ro
     - /tmp:/tmp

Bash’ing into the container shows ls -l /assets/scripts etc do exist.

Can anyone provide some guidance?

try writing to your log using {rewrite_path} this will output what the rewrite engine is rewriting to which may help you diagnose what the issue is.


log / stdout "{remote} {host} {uri} {rewrite_path}"

I think it’s because I was using the Golang docker image, Caddy being installed in /go/bin - so setting root / fixed the issue if I first capture the rewrite rule and passed it on with the placeholder: to /assets/styles/{1}

1 Like

Yeah, I’d think those rewrites wouldn’t work. For example:

rewrite {
	r [a-z]+\.js
	to /assets/scripts/

Would be trying to serve a request to /foo.js with /assets/scripts/, which isn’t a file and would 404.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.