Search code examples
wordpress.htaccesscontent-typemime

Matching on content-type in htaccess


I know I can use FilesMatch "\.html$" like this:

<FilesMatch "\.html$">
    Header set Pragma "public"
    Header set Cache-Control "public, must-revalidate, proxy-revalidate"
</FilesMatch>

But this won't help if the html is delivered as a SEO friendly URL (like wordpress does), right?

I there a way to match on content-type equals text/html?


Solution

  • If you're on Apache 2.4.10 or later, you can use expr= as

    Header set Pragma "public" "expr=%{CONTENT_TYPE} =~ m#text/html#"
    Header set Cache-Control "public, must-revalidate, proxy-revalidate" "expr=%{CONTENT_TYPE} =~ m#text/html#"
    

    See the documentation and examples on mod_headers and expr.