views:

79

answers:

1

This is a following to my yesterday question: http://stackoverflow.com/questions/1975416/trying-to-understand-the-vary-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!

A: 

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.

The Doctor What
AlexV
Still waiting for some clarifications...
AlexV
If different GET arguments are being sent over the wire, then they are different URLs and you don't have to worry about Vary.PATH_INFO lets you read extra path elements to a script: /foo.php/some/more/info will have PATH_INFO=/some/more/info for code inside foo.php
The Doctor What
OK, thanks for the extra info, but I'm still not sure about Vary: PATH_INFO...
AlexV
PATH_INFO isn't a vary, it's just a way to do more with your URL. Example: http://example.com/index.php/extra will execute the index.php script but PATH_INFO will be '/extra'. It is a different URL but it is the same PHP script. You won't need to vary, since the URL is different.
The Doctor What
AlexV
Yup. It's hard to explain. You just use $_SERVER['PATH_INFO'] -- note, that it doesn't exist unless additional paths exist. Try it out on a php_info() page. :-) It's in the Apache Environment section. If this solves your problem, I'll write it up as an answer. ;-)
The Doctor What