What is .htaccess ?
An .htaccess is a file controls how Apache interacts with website. When an .htaccess file is placed in domain’s 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.
How enable .htaccess in Website?
Simply you can add the file with full name “.htaccess” 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 code on that file.
.htaccess to Expires and Cache-Control headers
What is Cache-Control is a HTTP header:Cache-Control is a HTTP header that defines the amount of time and manner a file is to be cached.
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. the following example different ways to set the expiration periods by years,months and seconds.
how Cache-Control is a HTTP header works
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 .
.htaccess for Browser cache-control
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 :&lt;ifModule mod_headers.c&gt; &lt;filesMatch "\.(pg|jpeg|png|gif|js|ico|swf)$"&gt; Header set Cache-Control "public" &lt;/filesMatch&gt; &lt;filesMatch "\.(css)$"&gt; Header set Cache-Control "public" &lt;/filesMatch&gt; &lt;filesMatch "\.(js)$"&gt; Header set Cache-Control "private" &lt;/filesMatch&gt; &lt;filesMatch "\.(x?html?|php)$"&gt; Header set Cache-Control "private, must-revalidate" &lt;/filesMatch&gt; &lt;/ifModule&gt;
.htaccess for Gzip compression
You can use one of two Apache mods to enable HTTP gzip compression,mod_gzip and mod_deflate .
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’t matter if you use either Mod_gzip or enables gzip.
1,843 total views, 3 views today
Find Related Information