{"id":41481,"date":"2014-07-08T16:23:04","date_gmt":"2014-07-08T10:53:04","guid":{"rendered":"https:\/\/www.quickonlinetips.com\/archives\/?p=41481"},"modified":"2020-05-24T10:58:01","modified_gmt":"2020-05-24T05:28:01","slug":"vary-accept-encoding-header-with-htaccess","status":"publish","type":"post","link":"https:\/\/www.quickonlinetips.com\/archives\/2014\/07\/vary-accept-encoding-header-with-htaccess\/","title":{"rendered":"How to Add Vary: Accept-Encoding HTTP Header with .htaccess"},"content":{"rendered":"<p>Its a good idea to set <strong>Vary: Accept-Encoding<\/strong>\u00a0HTTP header response from your server, especially if you display different websites for various user agents and even to define if the caching tool should serve the gzip compressed file or not.<\/p>\n<p>First use the <a href=\"https:\/\/www.quickonlinetips.com\/projects\/http-headers-check\/\" target=\"_blank\" rel=\"noopener noreferrer\">HTTP headers check tool<\/a> to see the headers sent by your server. Do you see the Vary headers? If not then here is how to add it.<\/p>\n<h2>Add Vary: Accept-Encoding<\/h2>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-41535\" src=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding.png\" alt=\"vary accept encoding\" width=\"414\" height=\"193\" srcset=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding.png 414w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding-150x69.png 150w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding-300x139.png 300w\" sizes=\"(max-width: 414px) 100vw, 414px\" \/><\/p>\n<p>You need to add the following code below to the <em>.htaccess<\/em> file. This file resides on the server root and can be accessed via FTP. [Note it is a very powerful file and the wrong configuration can take your site down. Always keep a .htaccess backup, just in case you need to replace the original file.]<\/p>\n<p>I have been trying various combinations, and this code finally seems to work for our <a title=\"Get Faster Sites with SSD VPS Hosting\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/12\/knownhost-ssd-vps-hosting\/\">SSD hosting server<\/a>. Add this code below<\/p>\n<pre><code>&lt;IfModule mod_headers.c&gt;\r\nHeader set Vary \"Accept-Encoding\"\r\n&lt;\/IfModule&gt;<\/code><\/pre>\n<p>Now again test your site headers with the HTTP headers tool. Now the Vary header should appear.<\/p>\n<h3>Why Vary HTTP Header<\/h3>\n<p>If you read the <a href=\"https:\/\/developers.google.com\/search\/mobile-sites\/\" target=\"_blank\" rel=\"noopener noreferrer\">Google \u00a0guide<\/a> to developing smartphone-optimized websites, \u00a0you will note it helps <span style=\"color: #000000;\">Googlebot discover your mobile-optimized content faster! \u00a0The Vary header can also be used to easily guide\u00a0<span style=\"color: #222222;\">caching servers if they should\u00a0serve the page from cache or not by varying the user agent.<\/span><\/span><\/p>\n<p><span style=\"color: #000000;\"><span style=\"color: #222222;\"><strong>Using Gzip?<\/strong> Accept-Encoding value can help if you use the gzip compression of web resources to <a title=\"How to Increase Site Speed by 200% Easily\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2012\/02\/increase-site-speed\/\">increase site speed<\/a>. Now, most websites use gzip compression as it allows faster loading of web pages (most WordPress caching plugins do gzip compression automatically)<\/span><\/span>. But this Vary Accept-Encoding header can help browser caching services understand if it needs to load the gzip version or not.<\/p>\n<p>The first time I read about the vary header was when trying to implement Pagespeed on our server. I learned that PageSpeed will always respect Vary: Accept-Encoding and Vary headers on HTML files, and it is a great way to speed up your website by defining the variable.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Its a good idea to set Vary: Accept-Encoding\u00a0HTTP header response from your server, especially if you display different websites for&#8230;<\/p>\n","protected":false},"author":4,"featured_media":41535,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[6],"tags":[49],"class_list":["post-41481","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogging","tag-tutorials"],"_links":{"self":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/41481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/comments?post=41481"}],"version-history":[{"count":0,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/41481\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/media\/41535"}],"wp:attachment":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/media?parent=41481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/categories?post=41481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/tags?post=41481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}