This Htaccess inclusion can make your website faster!

Please find below my customized version of htaccess file I use with all almost all my web portals using apache web server.

AddDefaultCharset UTF-8

Options All -Indexes +FollowSymLinks

Header unset Pragma
Header append Vary Accept-Encoding

Header set Connection keep-alive

# BEGIN Cache-Control Headers

Header set Cache-Control "max-age=2592000, public"

Header set Cache-Control "max-age=604800, public"

Header set Cache-Control "max-age=604800, private"

Header set Cache-Control "max-age=216000, public, must-revalidate"

Header set Cache-Control "max-age=1, private, must-revalidate"

# END Cache-Control Headers

mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|xml|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType application/xhtml+xml "access plus 1 seconds"
ExpiresByType image/gif "access plus 2 weeks"
ExpiresByType image/png "access plus 2 weeks"
ExpiresByType image/jpg "access plus 2 weeks"
ExpiresByType image/jpeg "access plus 2 weeks"
ExpiresByType video/ogg "access plus 2 weeks"
ExpiresByType audio/ogg "access plus 2 weeks"
ExpiresByType video/mp4 "access plus 2 weeks"
ExpiresByType image/x-icon "access plus 2 weeks"
ExpiresByType text/css "access plus 2 weeks"
ExpiresByType text/javascript "access plus 2 weeks"
ExpiresByType application/javascript "access plus 2 weeks"
ExpiresByType application/x-javascript "access plus 2 weeks"

Leave a Reply

Your email address will not be published. Required fields are marked *