{"id":32188,"date":"2024-11-25T11:05:13","date_gmt":"2024-11-25T03:05:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32188\/"},"modified":"2024-11-25T11:05:13","modified_gmt":"2024-11-25T03:05:13","slug":"%e8%81%8a%e8%81%8awordpress%e6%80%8e%e4%b9%88%e9%80%9a%e8%bf%87header%e7%bb%99%e9%a1%b5%e9%9d%a2%e5%8f%91%e9%80%81%e5%8e%9f%e7%94%9fhttp%e5%a4%b4","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32188\/","title":{"rendered":"\u804a\u804aWordPress\u600e\u4e48\u901a\u8fc7header\u7ed9\u9875\u9762\u53d1\u9001\u539f\u751fHTTP\u5934"},"content":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\u5173\u4e8e\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5176\u4e2d\u4e3b\u8981\u8ddf\u5927\u5bb6\u804a\u4e00\u804awordpress\u600e\u4e48\u901a\u8fc7header\u7ed9\u9875\u9762\u53d1\u9001\u539f\u751fhttp\u5934\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u4e0b\u9762\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u5427\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u5e2e\u52a9\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/020\/63f5905717ed2611.jpg\" class=\"aligncenter\" title=\"\u804a\u804aWordPress\u600e\u4e48\u901a\u8fc7header\u7ed9\u9875\u9762\u53d1\u9001\u539f\u751fHTTP\u5934\u63d2\u56fe\" alt=\"\u804a\u804aWordPress\u600e\u4e48\u901a\u8fc7header\u7ed9\u9875\u9762\u53d1\u9001\u539f\u751fHTTP\u5934\u63d2\u56fe\" \/><\/p>\n<p>\u5728PHP\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u7528 header \u51fd\u6570\u6765\u53d1\u9001\u539f\u751f HTTP \u5934\uff0c\u4f46\u5728WordPress\u4e2d\u600e\u4e48\u53d1\u9001HTTP \u5934\u5462\uff1f<\/p>\n<p><strong>\u65b9\u6cd5\u4e00\uff1a\u81ea\u5df1\u5199\u4ee3\u7801<\/strong><\/p>\n<p>\u5c06\u4e0b\u9762\u7684\u4ee3\u7801\u653e\u5230\u5f53\u524d\u4e3b\u9898\u7684functions.php\u4e2d\u5373\u53ef\uff1a<\/p>\n<pre>\/**\n*&nbsp;&nbsp;\u5728\u7528\u6237\u767b\u9646\u7684\u60c5\u51b5\u4e0b\uff0c\u7ed9\u524d\u53f0\u6240\u6709\u9875\u9762\u6dfb\u52a0\u4e0d\u7f13\u5b58\u7684&nbsp;Cache-Control&nbsp;\u5934&nbsp;&nbsp;\n*\/\nfunction&nbsp;ludou_http_headers()&nbsp;{\n&nbsp;&nbsp;\/\/&nbsp;\u5224\u65ad\u7528\u6237\u662f\u5426\u767b\u9646\uff0c\u5e76\u4e14\u662f\u5728\u975e\u540e\u53f0\uff08\u524d\u53f0\uff09\u9875\u9762\n&nbsp;&nbsp;if(is_user_logged_in()&nbsp;&amp;amp;&amp;amp;&nbsp;!is_admin())&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;php\u7684header\u51fd\u6570\u53d1\u9001HTTP&nbsp;\u5934\n&nbsp;&nbsp;&nbsp;&nbsp;header('Cache-Control:&nbsp;no-store,&nbsp;no-cache,&nbsp;must-revalidate,&nbsp;max-age=0');\n&nbsp;&nbsp;}\n}\n\/*&nbsp;WordPress&nbsp;hook\n*&nbsp;\u7b2c\u4e00\u4e2a\u53c2\u6570\u503c&nbsp;wp&nbsp;\u662faction\u52a8\u4f5c\u540d\u79f0\uff0c\u6587\u6863\uff1ahttps:\/\/codex.wordpress.org\/Plugin_API\/Action_Reference\/wp\n*&nbsp;\u7b2c\u4e8c\u4e2a\u53c2\u6570\u503c&nbsp;ludou_http_headers&nbsp;\u662f\u4e0a\u9762\u7684\u51fd\u6570\u540d\u79f0\uff0c\u81ea\u5df1\u53d6\u540d\n*\/\nadd_action(&nbsp;'wp',&nbsp;'ludou_http_headers'&nbsp;);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5\u4e8c\uff1a\u7528\u63d2\u4ef6<\/strong><\/p>\n<blockquote><p>\n  HTTP Headers\uff1ahttps:\/\/wordpress.org\/plugins\/http-headers\/HTTP headers to improve web site security\uff1ahttps:\/\/wordpress.org\/plugins\/http-security\/\n<\/p><\/blockquote>\n<p>\u63a8\u8350\u5b66\u4e60\uff1a\u300a\u300b<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u804a\u804aWordPress\u600e\u4e48\u901a\u8fc7header\u7ed9\u9875\u9762\u53d1\u9001\u539f\u751fHTTP\u5934\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\u5173\u4e8e\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5176\u4e2d\u4e3b\u8981\u8ddf\u5927\u5bb6\u804a\u4e00\u804awordpress\u600e\u4e48\u901a\u8fc7header\u7ed9\u9875\u9762\u53d1\u9001\u539f\u751fhttp\u5934\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u4e0b\u9762\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u5427\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u5e2e\u52a9\u3002 \u5728PHP\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u7528 header \u51fd\u6570\u6765\u53d1\u9001\u539f\u751f HTTP \u5934\uff0c\u4f46\u5728WordPress\u4e2d\u600e\u4e48\u53d1\u9001HTTP \u5934\u5462\uff1f \u65b9\u6cd5\u4e00\uff1a\u81ea\u5df1\u5199\u4ee3\u7801 \u5c06\u4e0b\u9762\u7684\u4ee3\u7801\u653e\u5230\u5f53\u524d\u4e3b\u9898\u7684functions.php\u4e2d\u5373\u53ef\uff1a \/** *&nbsp;&nbsp;\u5728\u7528\u6237\u767b\u9646\u7684\u60c5\u51b5\u4e0b\uff0c\u7ed9\u524d\u53f0\u6240\u6709\u9875\u9762\u6dfb\u52a0\u4e0d\u7f13\u5b58\u7684&nbsp;Cache-Control&nbsp;\u5934&nbsp;&nbsp; *\/ function&nbsp;ludou_http_headers()&nbsp;{ &nbsp;&nbsp;\/\/&nbsp;\u5224\u65ad\u7528\u6237\u662f\u5426\u767b\u9646\uff0c\u5e76\u4e14\u662f\u5728\u975e\u540e\u53f0\uff08\u524d\u53f0\uff09\u9875\u9762 &nbsp;&nbsp;if(is_user_logged_in()&nbsp;&amp;amp;&amp;amp;&nbsp;!is_admin())&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;php\u7684header\u51fd\u6570\u53d1\u9001HTTP&nbsp;\u5934 &nbsp;&nbsp;&nbsp;&nbsp;header(&#8216;Cache-Control:&nbsp;no-store,&nbsp;no-cache,&nbsp;must-revalidate,&nbsp;max-age=0&#8217;); &nbsp;&nbsp;} } \/*&nbsp;WordPress&nbsp;hook *&nbsp;\u7b2c\u4e00\u4e2a\u53c2\u6570\u503c&nbsp;wp&nbsp;\u662faction\u52a8\u4f5c\u540d\u79f0\uff0c\u6587\u6863\uff1ahttps:\/\/codex.wordpress.org\/Plugin_API\/Action_Reference\/wp *&nbsp;\u7b2c\u4e8c\u4e2a\u53c2\u6570\u503c&nbsp;ludou_http_headers&nbsp;\u662f\u4e0a\u9762\u7684\u51fd\u6570\u540d\u79f0\uff0c\u81ea\u5df1\u53d6\u540d *\/ add_action(&nbsp;&#8216;wp&#8217;,&nbsp;&#8216;ludou_http_headers&#8217;&nbsp;); \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5\u4e8c\uff1a\u7528\u63d2\u4ef6 HTTP Headers\uff1ahttps:\/\/wordpress.org\/plugins\/http-headers\/HTTP headers to improve web site security\uff1ahttps:\/\/wordpress.org\/plugins\/http-security\/ \u63a8\u8350\u5b66\u4e60\uff1a\u300a\u300b \u4ee5\u4e0a\u5c31\u662f\u804a\u804aWordPress\u600e\u4e48\u901a\u8fc7header\u7ed9\u9875\u9762\u53d1\u9001\u539f\u751fHTTP\u5934\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-32188","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=32188"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32188\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}