Only Apache and LiteSpeed use .htaccess, it wouldn’t work with other web servers such as Nginx.
Isn’t there an option to cache HTTP headers response?
I downloaded and tested the first caching plugin I found in the repo (https://www.ads-software.com/plugins/wp-super-cache/) and it had a “Cache HTTP headers with page content”, which I enabled. I also created a custom HTTP header with NinjaFirewall: foo: bar
Here’re the results.
First, page is not cached yet:
$ curl -I https://localhost/
HTTP/1.1 200 OK
Server: nginx/1.22.1
Date: Fri, 03 Nov 2023 09:10:22 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
Vary: Accept-Encoding, Cookie
foo: bar
X-WP-Cache: MISS
Then the same page, but cached this time:
$ curl -I https://localhost/
HTTP/1.1 200 OK
Server: nginx/1.22.1
Date: Fri, 03 Nov 2023 09:10:24 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
Vary: Accept-Encoding, Cookie
foo: bar
X-WP-Cache: HIT
My foo: bar
header is always returned.