通过在.htaccess中启用gzip提高magento速度
如果这是一个noob问题,我深表歉意,但我最近才知道,在magento中启用gzip可以提高应用程序的速度。但magento目录中的.htaccess文件似乎太多了。那么,我必须在所有目录上启用还是只在通过在.htaccess中启用gzip提高magento速度,.htaccess,magento,.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/ww
/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
会暴露您的加密密钥和数据库访问凭据,如果启用了对MySQL的远程访问,这是一个特别致命的错误。你刚刚把你王国的钥匙交给了外面的世界
要启用deflate/gzip,首先您的apache服务器必须启用适当的模块(mod_deflate)。然后在Magento根文件夹的.htaccess文件中查找设置并启用压缩。Magento为您预安装了此文件,但其中的行已被注释掉
要查看您的系统是否支持deflate/gzip,请创建一个
文件,运行它并查找正在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
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文件启用gzip:
##### files compression for better site speed #####
<IfModule mod_deflate.c>
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
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
</IfModule>
######文件压缩以提高网站速度#####
AddOutputFilterByType泄气文本/普通
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE应用程序/xml
AddOutputFilterByType DEFLATE应用程序/xhtml+xml
AddOutputFilterByType DEFLATE应用程序/rss+xml
AddOutputFilterByType DEFLATE应用程序/javascript
AddOutputFilterByType DEFLATE应用程序/x-javascript
浏览器匹配^Mozilla/4 gzip纯文本/html
浏览器匹配^Mozilla/4\.0[678]无gzip
BrowserMatch\bMSIE!没有gzip!仅限gzip文本/html
SetEnvIfNoCase请求_URI\(?:gif | jpe?g | png)$no gzip不变
标头附加变量用户代理env=!不要改变
你也可以参考我的博客: