Question

I just did a major update in my WordPress environment tonight to the latest version, and got an internal server error on the site. I then did a full inspection to see where the issue was coming from. I think I found the culprit...When I commented out the following line in my .htaccess file, the site came back...

# SGO Unset Vary
  Header unset Vary
# SGO Unset Vary END

In what situations do we ever need Header unset Vary in our .htaccess file?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top