Php – Content negotiation and HTTP headers in PHP

cachinghttpPHPPROXY

This is a following to my yesterday question:
What is the function of the "Vary: Accept" HTTP header?

I have a .php that can be served with different MIME types. To do this I use "Vary: Accept" HTTP header (which is confirmed to be correct). But what if the same document (with the same URL) can be served in many languages (and this page can be cached by proxies)? I know this is bad design, but it can happens sometimes. What in that particular case would be the way to do this.

J.J. gave a link ( http://www.w3.org/Protocols/HTTP/Issues/vary-header.html ) to a discussion where someone wanted to use the Vary HTTP header for a document that can be served in two different languages:

For the request/variant scenario you
listed a server SHOULD NOT BE USING
VARY: Sorry to shout, but I want it
to be real clear. Vary: is strictly
for those cases where it's hopeless or
excessively complicated for a proxy to
replicate what the server would do
(other than storing header and doing
strict request header equality
comparisons on subsequent requests).

I think the solution lies in the link provided by J.J., but I'm not sure what is it and how to implement it in PHP.

Thanks for your lights!

Best Answer

I think that if you are serving multiple languages via the same URL with no GET or POST values based only upon the Accept-Language header then you have to use Vary.

If you are using GET arguments, then you don't need the vary, just set the caching headers correctly.

If you want to use the same document, but can vary the URLs, then you can use the PATH_INFO environment variable to emulate other URLs but using the same document.

His URI header scheme only works if you have different URLs.