{"id":86,"date":"2016-10-08T11:39:33","date_gmt":"2016-10-08T11:39:33","guid":{"rendered":"https:\/\/www.xsofthost.com\/Blogs\/?p=86"},"modified":"2017-09-01T12:20:22","modified_gmt":"2017-09-01T12:20:22","slug":"speed-website-using-htaccess-file","status":"publish","type":"post","link":"https:\/\/www.xsofthost.com\/help\/speed-website-using-htaccess-file\/","title":{"rendered":"Speed up website using .htaccess file"},"content":{"rendered":"<h2>What is .htaccess ?<\/h2>\n<p>An <strong>.htaccess<\/strong> is a file controls how Apache interacts with website. When an .htaccess file is placed in domain\u2019s directory, the .htaccess file is detected and executed by Apache and use or overrides the apache settings for the single website.With .htaccess files you can create redirects, rewrite URLs on your website, create password protected directories and others.<\/p>\n<h2>How enable .htaccess in Website?<\/h2>\n<p>Simply you can add the file with full name &#8220;.htaccess&#8221; on the root of website to configure the domain itself and use the Apache configuration especially for this domain.then you can start add the special configuration\u00a0 code on that file.<\/p>\n<h2>.htaccess to Expires and Cache-Control headers<\/h2>\n<p><strong>What is Cache-Control is a HTTP header<\/strong>:Cache-Control is a HTTP header that defines the amount of time and manner a file is to be cached.<\/p>\n<p>In order to add browser caching to website, you will need to set the date for when the cache expires. This date is of course flexible, and the optimal and responsible cache time for your site can differ depending on the type of website you are running.\u00a0 the following example different ways to set the expiration periods by years,months and seconds.<\/p>\n<pre><pre class=\"brush: bash; title: ; notranslate\" title=\"\"> &amp;amp;amp;amp;amp;lt;IfModule mod_expires.c&amp;amp;amp;amp;amp;gt;\r\n# Enable Expirations Mode\r\nExpiresActive On\r\n# Website Favicon Icon\r\nExpiresByType image\/x-icon &quot;access plus 1 year&quot;\r\n# Images Types\r\nExpiresByType image\/gif &quot;access plus 1 month&quot;\r\nExpiresByType image\/png &quot;access plus 1 month&quot;\r\nExpiresByType image\/jpg &quot;access plus 1 month&quot;\r\nExpiresByType image\/jpeg &quot;access plus 1 month&quot;\r\nExpiresByType image\/svg+xml &quot;access plus 1 month&quot;\r\nExpiresByType text\/x-javascript &quot;access 1 month&quot;\r\n# Support WebSite Types With Second Expiration Option\r\nExpiresByType text\/css &quot;access plus 604800 seconds&quot;\r\nExpiresByType text\/javascript &quot;access plus 216000 seconds&quot;\r\nExpiresByType application\/javascript &quot;access plus 216000 seconds&quot;\r\nExpiresByType application\/x-javascript &quot;access plus 216000 seconds&quot;\r\nExpiresByType text\/html &quot;access plus 600 seconds&quot;\r\nExpiresByType application\/xhtml+xml &quot;access plus 600 seconds&quot; \r\n&amp;amp;amp;amp;amp;lt;\/IfModule&amp;amp;amp;amp;amp;gt;\r\n <\/pre>\n<h3>how <strong>Cache-Control is a HTTP header<\/strong> works<\/h3>\n<p>When a new visitor browse website all the files like scripts, CSS styles and images are downloaded to the client temporary cache browser software. But when the user returns to same website it will reload the files from the cache rather than downloading them all again and this is one of the efficient configuration that my speed the web site .<\/p>\n<h2>.htaccess for Browser cache-control<\/h2>\n<p>Browser cache control is directly related with Cache-Control is a HTTP header and according to the Apache documentation provides directives to control and modify HTTP request and response headers. Headers can be merged, replaced or removed. This is an example on how to add this feature code inside htaccess file :<\/p>\n<pre><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n\r\n&amp;amp;lt;ifModule mod_headers.c&amp;amp;gt;\r\n  &amp;amp;lt;filesMatch &quot;\\.(pg|jpeg|png|gif|js|ico|swf)$&quot;&amp;amp;gt;\r\n    Header set Cache-Control &quot;public&quot;\r\n  &amp;amp;lt;\/filesMatch&amp;amp;gt;\r\n  &amp;amp;lt;filesMatch &quot;\\.(css)$&quot;&amp;amp;gt;\r\n    Header set Cache-Control &quot;public&quot;\r\n  &amp;amp;lt;\/filesMatch&amp;amp;gt;\r\n  &amp;amp;lt;filesMatch &quot;\\.(js)$&quot;&amp;amp;gt;\r\n    Header set Cache-Control &quot;private&quot;\r\n  &amp;amp;lt;\/filesMatch&amp;amp;gt;\r\n  &amp;amp;lt;filesMatch &quot;\\.(x?html?|php)$&quot;&amp;amp;gt;\r\n    Header set Cache-Control &quot;private, must-revalidate&quot;\r\n  &amp;amp;lt;\/filesMatch&amp;amp;gt;\r\n&amp;amp;lt;\/ifModule&amp;amp;gt;\r\n\r\n<\/pre>\n<h2>.htaccess for Gzip compression<\/h2>\n<p>To Optimize Website With GZIP Compression , we need to understand how\u00a0Optimize Your Site With GZIP Compression do. Website GZIP compression makes it possible to reduce the file size of a web file (like HTML, PHP, CSS and Javascript files) and reduce bandwidth between 50-70% less of its original size before these files get sent to the browser of a user.<\/p>\n<p>You can use one of two Apache mods to enable HTTP gzip compression,<strong>mod_gzip<\/strong> and <strong>mod_deflate <\/strong>.<\/p>\n<p>Mod_gzip enables gzip compression and mod_deflate makes it possible to compress the output from your server before it is being sent to your visitor.and actually both mods are the same , so it doesn&#8217;t matter if you use either Mod_gzip or enables gzip.<\/p>\n<p>To Use Apache Mod_gzip :<\/p>\n<pre><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&amp;amp;lt;ifModule mod_gzip.c&amp;amp;gt;\r\nmod_gzip_on Yes\r\nmod_gzip_dechunk Yes\r\nmod_gzip_item_include file .(html?|txt|css|js|php|pl)$\r\nmod_gzip_item_include handler ^cgi-script$\r\nmod_gzip_item_include mime ^text\/.*\r\nmod_gzip_item_include mime ^application\/x-javascript.*\r\nmod_gzip_item_exclude mime ^image\/.*\r\nmod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*\r\n&amp;amp;lt;\/ifModule&amp;amp;gt; \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Using Apache\u00a0 mod_deflate:<\/p>\n<pre><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&amp;amp;lt;IfModule mod_deflate.c&amp;amp;gt;\r\nAddOutputFilterByType DEFLATE text\/html\r\nAddOutputFilterByType DEFLATE text\/css\r\nAddOutputFilterByType DEFLATE text\/javascript\r\nAddOutputFilterByType DEFLATE text\/xml\r\nAddOutputFilterByType DEFLATE text\/plain\r\nAddOutputFilterByType DEFLATE image\/x-icon\r\nAddOutputFilterByType DEFLATE image\/svg+xml\r\nAddOutputFilterByType DEFLATE application\/rss+xml\r\n&amp;amp;lt;\/IfModule&amp;amp;gt;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is .htaccess ? An .htaccess is a file controls how Apache interacts with website. When an .htaccess file is placed in domain\u2019s directory, the .htaccess file is detected and executed by Apache and use or overrides the apache settings for the single website.With .htaccess files you can create redirects, rewrite URLs on your website, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":274,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[32,178,33,74],"_links":{"self":[{"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/posts\/86"}],"collection":[{"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/comments?post=86"}],"version-history":[{"count":45,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":1430,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/posts\/86\/revisions\/1430"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/media\/274"}],"wp:attachment":[{"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}