Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boosting magento speed by enabling gzip in .htaccess

Apologies if this is a noob question but i recently came to know that by enabling gzip in magento boosts the application speed. But there seems to be too many .htaccess files in magento directory. So do i have to enabled on all the directories or only on /var/www/html/magento/.htaccess?

/var/www/html/magento/.htaccess
/var/www/html/magento/.htaccess.sample
/var/www/html/magento/app/.htaccess
/var/www/html/magento/downloader/.htaccess
/var/www/html/magento/downloader/template/.htaccess
/var/www/html/magento/errors/.htaccess
/var/www/html/magento/includes/.htaccess
/var/www/html/magento/lib/.htaccess
/var/www/html/magento/media/.htaccess
/var/www/html/magento/media/customer/.htaccess
/var/www/html/magento/media/downloadable/.htaccess
/var/www/html/magento/pkginfo/.htaccess
/var/www/html/magento/var/.htaccess
like image 612
fear_matrix Avatar asked Feb 07 '13 06:02

fear_matrix


1 Answers

.htaccess settings flow from the top down.

Don't mess with subdirectory .htaccess files below the Magento root unless you know what you're doing, they're there to secure the Magento system. As an example, messing with app/etc/.htaccess can expose your encryption key and database access credentials, a particularly fatal mistake if you've enabled remote access to MySQL. You've just given the outside world the keys to your kingdom.

To enable deflate/gzip, first your apache server must have the proper module enabled (mod_deflate). Then look up the settings in the .htaccess file in your Magento root folder and enable compression. Magento preinstalls this for you, but with the lines commented out.

To see if your system supports deflate/gzip, create a <?php phpinfo(); ?> file, run it and look for mod_deflate being loaded under apache2handler. Following is a sample

Loaded Modules core mod_log_config mod_logio prefork http_core mod_so mod_actions
               mod_alias mod_auth_basic mod_authn_file mod_authz_default 
               mod_authz_groupfile mod_authz_host mod_authz_user mod_autoindex 
               mod_cgi mod_deflate mod_dir mod_env mod_expires mod_fastcgi 
               mod_headers mod_include mod_mime mod_negotiation mod_php5 
               mod_reqtimeout mod_rewrite mod_setenvif mod_ssl mod_status 
               mod_suexec

Magento's preloaded .htaccess section needs some modifications to enable deflate/gzip Remove the # in front of the appropriate lines to enable compression as follows:

############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip

    # Insert filter on all content
    ###SetOutputFilter DEFLATE
    # Insert filter on selected content types only
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript

    # Netscape 4.x has some problems...
    #BrowserMatch ^Mozilla/4 gzip-only-text/html

    # Netscape 4.06-4.08 have some more problems
    #BrowserMatch ^Mozilla/4\.0[678] no-gzip

    # MSIE masquerades as Netscape, but it is fine
    #BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # Don't compress images
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary

like image 110
Fiasco Labs Avatar answered Nov 25 '22 14:11

Fiasco Labs