问题描述
我终于得到了建立一个VPS托管帐户,这允许我使用mod_deflate模块和mod_header(当然)。我试图让我的网站更快的YSlow的指导方针,其中包括使用gzip压缩(通过mod_deflate模块)的页面,并设置一个长的到期头。
会采取什么的.htaccess code这个样子呢?我见过各种各样的例子,但我不知道是什么会是什么样子,以适应这些参数。
例如
#mod_deflate模块
< IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE文/文为text / html文本/纯文本/ XML文本/ CSS应用程序/ x-的JavaScript应用程序/ JavaScript的
SetEnvIfNoCase REQUEST_URI(?:EXE |?吨GZ |拉链| ISO |焦油| BZ2 |坐| RAR | PNG | JPG | GIF | JPEG | FLV | SWF)$无gzip的不要,各不相同
BrowserMatch ^的Mozilla / 4 GZIP只-text / html的
BrowserMatch ^的Mozilla / 4 \。[0678]无GZIP
BrowserMatch \ bMSIE!没有GZIP!GZIP只-text / html的
头追加因人而异用户代理包膜=!不,变化
< / IfModule>
海峡从 HTML5样板
< IfModule mod_deflate.c>
#力紧缩的错位头
#developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
< IfModule mod_setenvif.c>
< IfModule mod_headers.c>
SetEnvIfNoCase ^(接受-EncodXng | X-CEPT-编码| X {15} |〜{15} | - {15})$ ^((GZIP |?放气)\ S * \ S *)+ | [X〜 - ] {4,13} $ HAVE_Accept,编码
RequestHeader追加接受编码的gzip,紧缩ENV = HAVE_Accept,编码
< / IfModule>
< / IfModule>
#HTML,TXT,CSS,JavaScript的,JSON,XML,HTC:
< IfModule filter_module>
FilterDeclare COM $ P $干燥综合征
FilterProvider COM $ P $干燥综合征DEFLATE RESP = Content-Type的$ text / html的
FilterProvider COM $ P $干燥综合征DEFLATE RESP = Content-Type的$文本/ CSS
FilterProvider COM $ P $干燥综合征DEFLATE RESP = Content-Type的$ text / plain的
FilterProvider COM $ P $干燥综合征DEFLATE RESP =内容类型$为text / xml
FilterProvider COM $ P $干燥综合征DEFLATE RESP = Content-Type的$文本/ x分量
FilterProvider COM $ P $干燥综合征DEFLATE RESP =内容类型$应用程序/ JavaScript的
FilterProvider COM $ P $干燥综合征DEFLATE RESP =内容类型$应用程序/ JSON
FilterProvider COM $ P $干燥综合征DEFLATE RESP =内容类型$应用程序/ XML
FilterProvider COM $ P $干燥综合征DEFLATE RESP =内容类型$应用程序/ xhtml + xml
FilterProvider COM $ P $干燥综合征DEFLATE RESP =内容类型$应用程序/的RSS + XML
FilterProvider COM $ P $干燥综合征DEFLATE RESP =内容类型$应用程序/原子+ XML
FilterProvider COM $ P $干燥综合征DEFLATE RESP =内容类型$应用程序/ vnd.ms-fontobject
FilterProvider COM $ P $干燥综合征DEFLATE RESP = Content-Type的$图像/ SVG + XML
FilterProvider COM $ P $干燥综合征DEFLATE RESP =内容类型$应用程序/ x-字体,TTF
FilterProvider COM $ P $干燥综合征DEFLATE RESP =内容类型$字型/ OpenType字体
的FilterChain COM $ P $干燥综合征
FilterProtocol COM $ P $干燥综合征DEFLATE变化= YES,字节范围=无
< / IfModule>
<!IfModule mod_filter.c>
#旧的Apache版本
AddOutputFilterByType DEFLATE text / html的文本/纯文本/ css的应用程序/ JSON
AddOutputFilterByType DEFLATE应用程序/ JavaScript的
AddOutputFilterByType DEFLATE文/ XML应用程序/ XML文本/ x分量
AddOutputFilterByType DEFLATE是application / xhtml + XML应用程序/ RSS + XML应用程序/原子+ XML
AddOutputFilterByType DEFLATE图像/ SVG + XML应用程序/ vnd.ms-fontobject应用程序/ x-字体TTF字库/ OpenType字体
< / IfModule>
< / IfModule>
和
< IfModule mod_expires.c>
ExpiresActive上
#也许是更好的白名单到期规则?也许。
ExpiresDefault进入加1月
在FF 3.6#cache.appcache需要重新申请(THX雷米〜介绍HTML5)
ExpiresByType文本/缓存清单的访问以及0秒
#您的文档HTML
ExpiresByType text / html的连接以及0秒
# 数据
ExpiresByType文本/ xml的访问以及0秒
ExpiresByType应用程序/ xml的访问以及0秒
ExpiresByType应用/ JSON的连接以及0秒
#RSS提要
ExpiresByType应用程序/ RSS + XML进入加1小时的
#网站图标(不能重命名)
ExpiresByType图像/ X-图标进入加1周
#媒体:图像,视频,音频
ExpiresByType图像/ GIF进入加1月
ExpiresByType图像/ PNG进入加1月
ExpiresByType图像/ JPG进入加1月
ExpiresByType为image / jpeg进入加1月
ExpiresByType视频/ OGG进入加1月
ExpiresByType音频/ OGG进入加1月
ExpiresByType视频/ MP4进入加1月
ExpiresByType视频/ WEBM进入加1月
#HTC文件(css3pie)
ExpiresByType文/ x分量进入加1月
#Webfonts
ExpiresByType字体/ TrueType字体进入加1月
ExpiresByType字型/ OpenType字体进入加1月
ExpiresByType应用程序/ x-字体WOFF进入加1月
ExpiresByType图像/ SVG + XML进入加1月
ExpiresByType应用程序/ vnd.ms-fontobject进入加1月
#CSS和JavaScript
ExpiresByType文本/ CSS进入加1年
ExpiresByType应用程序/ JavaScript的进入加1年
ExpiresByType文/ JavaScript的进入加1年
< IfModule mod_headers.c>
包头追加的Cache-Control公
< / IfModule>
< / IfModule>
也YSlow的:除去ETAG:
#FileETag无是不够的,每个服务器。
< IfModule mod_headers.c>
头取消设置的ETag
< / IfModule>
#由于we`re发送不远的将来到期时,我们不需要ETag的静态内容。
#developer.yahoo.com/performance/rules.html#etags
FileETag无
I've finally gotten a VPS hosting account set up this allows me to use mod_deflate and mod_header (of course). I'm attempting to make my site faster by YSlow's guidelines which include gzipping (via mod_deflate) the pages and setting a long expire header.
What would the .htaccess code for this look like? I've seen various examples but I'm wondering what it would look like to fit those parameters.
For example
# Mod_deflate
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|iso|tar|bz2|sit|rar|png|jpg|gif|jpeg|flv|swf)$ no-gzip dont-vary
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.[0678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent env=!dont-vary
</IfModule>
Strait from the html5 boilerplate
<IfModule mod_deflate.c>
# force deflate for mangled headers
# developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
# HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
<IfModule filter_module>
FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf
FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype
FilterChain COMPRESS
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
</IfModule>
<IfModule !mod_filter.c>
# Legacy versions of Apache
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</IfModule>
</IfModule>
and
<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault "access plus 1 month"
# cache.appcache needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Your document html
ExpiresByType text/html "access plus 0 seconds"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
# RSS feed
ExpiresByType application/rss+xml "access plus 1 hour"
# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"
# Media: images, video, audio
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# HTC files (css3pie)
ExpiresByType text/x-component "access plus 1 month"
# Webfonts
ExpiresByType font/truetype "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
<IfModule mod_headers.c>
Header append Cache-Control "public"
</IfModule>
</IfModule>
also in YSlow: remove etag:
# FileETag None is not enough for every server.
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
# Since we`re sending far-future expires, we don't need ETags for static content.
# developer.yahoo.com/performance/rules.html#etags
FileETag None
这篇关于mod_deflate模块和mod_header设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!