When is it necessary to have Header unset Vary in .htaccess

Header unset Vary

This is probably a workaround for a supposed bug in Apache (#58231)*1 that could prevent certain caching proxies from caching the response when the Vary: Host HTTP response header is set. Apache might be setting this automatically when querying the HTTP_HOST server variable in a mod_rewrite RewriteCond directive (or Apache Expression).

*1 Although this is arguably a bug in the cache, not Apache. The Apache behaviour is “by design” and a Vary: Host header should not prevent a cache from working since this is really the default behaviour.

However, if you are varying the HTTP response based on other elements of the request (such as the Accept, Accept-Language or User-Agent HTTP request headers) then the Vary HTTP response header should be set appropriately and should not simply be unset.

I am surprised, however, that this directive would cause an error. It implies that mod_headers is not installed – which is “unlikely”. However, you can protect against this and surround the directive in an <IfModule> directive. For example:

# SGO Unset Vary
<IfModule mod_headers.c>
  Header unset Vary
</IfModule>
# SGO Unset Vary END

(From the indentation of the directive in your question it almost looks like this <IfModule> wrapper was missing?)

Now, the Header directive will be processed only if mod_headers is installed.