Regex in a Pages _headers file?

Question about using a _headers file with a Pages project: does it support regex? For example, would the following work?

    Cache-Control: public, max-age=31536000, immutable
    CDN-Cache-Control: public, max-age=31536000, immutable
    X-Content-Type-Options: nosniff

I currently use a Worker for this, but after one of my posts went semi-viral yesterday and blew through my monthly limit, am wondering whether I’m better off doing it through _headers if that’s possible.

(Also asked on the Discord.)

Unfortunately not, you can’t use Regex in _headers.

The logic for parsing _headers is open source in the Pages asset-server if you wanted to take a look:

1 Like

Will do. Thanks!

Although not officially supported, it does seem that the regex string is just concatenated, so you might be able to get something working:

1 Like

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