开发者

Should you set Vary: user-agent header if using mod_rewrite based on user agent?

I'm trying to display a differently-formatted page to mobile browsers using mod_rewrite based on the user-agent.

If I use a rewrite condition based 开发者_Go百科on the user-agent to show different content, should I also set a Vary: user-agent header? If so, how do I configure apache to do that?


Yes, you should set the Vary header. HTTP/1.1’s section 14.44 Vary spells it out quite clearly. Fortunately, mod_rewrite’s RewriteCond helpfully states that

If a HTTP header is used in a condition this header is added to the Vary header of the response in case the condition evaluates to to true for the request. It is not added if the condition evaluates to false for the request. Adding the HTTP header to the Vary header of the response is needed for proper caching.

So you should verify that your configuration sets the header properly, but it should Just Work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜