Confusing headers behaviour

Excellent, cheers!

I get that there isn’t an example of it being used to match file extensions, but I don’t think the absence of an example suggests it doesn’t work. Otherwise, that would suggest that :placeholder doesn’t work at all, since there isn’t a single example of it on that page. I don’t think that’s the case, and I don’t think that’s how folks interpret documentation.

I think it’s better to explain how it works, rather than give an incomplete description, then try and fill in the gaps with exceptions. If I’ve understood how it works correctly, I think this describes it:

You can use * at the end of a pattern to match anything that appears afterwards. This makes the pattern a “starts with” match. So /foo/* will match any URL that starts with /foo/, including /foo/ itself, but also /foo/bar/ and /foo/hello/world/yo.html.

Warning: Although * can only be used at the end of a pattern, Netlify does not validate this. Instead, any pattern characters after the first * are simply discarded. Netlify will silently accept a rule like /posts/*.jpg, but it will not behave as you intend. It will be interpreted as /posts/*, so the rule will apply for /posts/cat.jpg, but it will also apply for /posts/data.json.

You need a strong warning here, because no one would include a rule like /posts/*.jpg expecting the .jpg to be ignored.

You wouldn’t need the strong warning if Netlify caught the issue at build time, and failed the build with a message like “Header rule error: * can only appear at the end of a pattern, see [url] for more details”.
This is my preference, as I would have discovered the issue at build time, rather than in production.

Netlify App - in this deploy I had a header rule like /*.c.*, which is being reinterpreted as /* without warning.

Cheers! I’ll put all that in a separate reply.

2 Likes