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

标签 .htaccess magento

抱歉,如果这是一个菜鸟问题,但我最近知道通过在 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

最佳答案

.htaccess 设置自上而下流动。

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

要启用 deflate/gzip,首先您的 apache 服务器必须启用正确的模块 ( mod_deflate )。然后在 Magento 根文件夹中的 .htaccess 文件中查找设置并启用压缩。 Magento 为您预先安装了它,但注释掉了这些行。

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

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 的预加载 .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

关于.htaccess - 通过在 .htaccess 中启用 gzip 来提高 magento 速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14744720/

相关文章:

php - 使用 PHP/htaccess/mod_rewrite 强制使用 www 前缀

magento - 在 Magento 中获取购物车详细信息

javascript - 当我在 requirejs 中时,如何调用全局加载的 api?

mysql - 导入 magento 数据库时遇到问题

WordPress Woocommerce 网站 : Force SSL on Account page causes Internal Server Error

php - 加载特定的 PHP 版本

mysql - 如何获取此类错误的表 - SQLSTATE [23000] : Integrity constraint violation: 1062

magento - Magento 中的废弃购物车报告在哪里?

reactjs - .htaccess 机器人代理

WordPress 管理员卡在 https,如何关闭它?