1

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!

Community
  • 1
  • 1
AlexV
  • 22,658
  • 18
  • 85
  • 122

1 Answers1

0

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.

docwhat
  • 11,435
  • 6
  • 55
  • 54
  • In fact there is either a $_GET in the URL (different URLs in that case) OR an hidden $_GET language variable sent by Apache (via .htaccess - in that case same URL). Can you please elaborate on your paragraphs 2 & 3. Not sure I understand... – AlexV Dec 30 '09 at 16:26
  • 1
    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 – docwhat Jan 05 '10 at 17:41
  • 1
    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. – docwhat Jan 06 '10 at 01:34
  • Ohh I see it's like a GET but without the ? and & (and won't be in $_GET superglobal)... How do you retrieve the PATH_INFO in your script? Using $_SERVER['REQUEST_URI']? PHP function parse_url? – AlexV Jan 06 '10 at 13:43
  • 1
    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. ;-) – docwhat Jan 07 '10 at 01:42