开发者

What HTTP header RESPONSES should I be explicitly setting when I output a webpage?

开发者 https://www.devze.com 2023-01-17 16:14 出处:网络
So I just now learned of the X-Robots-Tag which can be set as part of a server response header.Now that I have learned about this particular field, I am wondering if there are any other specific field

So I just now learned of the X-Robots-Tag which can be set as part of a server response header. Now that I have learned about this particular field, I am wondering if there are any other specific fields I should be setting when开发者_运维问答 I output a webpage via PHP? I did see this list of responses, but what should I be manually setting? What do you like to set manually?

Restated, in addition to...

header('X-Robots-Tag: noindex, nofollow, noarchive, nosnippet', true);

...what else should I be setting?

Thanks in advance!


You don't necessarily need to set any of them manually, and I don't send any unless absolutely necessary: most response headers are the web server's job, not the application's (give or take Location & situational cache-related headers).

As for the "X-*" headers, the X implies they aren't "official," so browsers may or may not interpret them to mean anything - like, you can add an arbitrary "X-My-App-Version" header to a public project to get a rough idea of where people are using it, but it's just extra info unless the requester knows what to do with it.

I think most X-headers are more commonly delivered via HTML as meta tags already. For example, <meta name="robots" content="noindex, nofollow, (etc)" />, which does the same as X-Robots-Tag. That's arguably better handled with the meta tag version anyway, since it won't trip over output buffering as header() can do, and it will be naturally cached since it's part of the page.


These are headers from Stackoverflow (this page), so the answer is, probably none. You don't want your site indexed (noindex)?

Status=OK - 200
Cache-Control=public, max-age=60
Content-Type=text/html; charset=utf-8
Content-Encoding=gzip
Expires=Tue, 28 Sep 2010 01:23:00 GMT
Last-Modified=Tue, 28 Sep 2010 01:22:00 GMT
Vary=*
Set-Cookie=usr=t=&s=; domain=.stackoverflow.com; expires=Mon, 28-Mar-2011 01:22:00 GMT; path=/; HttpOnly
Date=Tue, 28 Sep 2010 01:21:59 GMT
Content-Length=6929

This header comes handy to me. Characters are displayed correctly, even if meta tag is missing.

Content-Type: text/html; charset=utf-8
0

精彩评论

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

关注公众号