通过在.htaccess中启用gzip来提升magento速度

fea*_*rix 10 .htaccess magento

抱歉,如果这是一个noob问题,但我最近才知道通过在magento中启用gzip可以提高应用程序的速度.但magento目录中似乎有太多.htaccess文件.所以我必须在所有目录上启用或仅启用/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
Run Code Online (Sandbox Code Playgroud)

Fia*_*abs 22

.htaccess设置从上到下流动.

不要弄乱Magento根目录下的子目录.htaccess文件,除非你知道你在做什么,他们就是为了保护Magento系统.例如,搞乱app/etc/.htaccess可能会暴露您的加密密钥和数据库访问凭据,如果您启用了对MySQL的远程访问,这是一个特别致命的错误.你刚刚给了外面世界你王国的钥匙.

要启用deflate/gzip,首先必须启用apache服务器(mod_deflate).然后在Magento根文件夹中查找.htaccess文件中的设置并启用压缩.Magento为您预装了这个,但线条已经注释掉了.

要查看您的系统是否支持deflate/gzip,请创建一个<?php phpinfo(); ?>文件,运行它并查找在apache2handler下加载的mod_deflate.以下是一个示例

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
Run Code Online (Sandbox Code Playgroud)

Magento的预加载.htaccess部分需要进行一些修改以启用deflate/gzip删除相应行前面的#以启用压缩,如下所示:

############################################
## 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
Run Code Online (Sandbox Code Playgroud)