About”.htaccess”
Unix、Linux系统或者是任何版本的Apache Web服务器都是支持.htaccess。通过修改或者启用.htaccess文件我们可以实现:网页301重定向、自定义404错误页面、改变文件扩展名、允许/阻止特定的用户或者目录的访问、禁止目录列表、配置默认文档等功能。
文件处于服务器网站目录下,部分服务器会将其设置成隐藏文件。我们可以用ftp工具Filezilla让他现形,操作:链接服务器-服务器-强制显示隐藏文件。
通过改动.htaccess来为网站提速
使用Chrome浏览器安装YSlow
插件,然后打开我们希望评分的网页,待网站全部读取完毕之后我们点击YSlow图标-Run test进行评分。

其中可通过更改.htaccess文件进行优化的是:
- Add Expires headers(添加周期头)
- Compress components with gzip(Gzip压缩)
- Configure entity tags (ETags)(配置实体标签设置ETAG)
<IfModule mod_expires.c> ExpiresActive On ExpiresDefault A3600 ExpiresByType image/gif A2592000 ExpiresByType image/png A2592000 ExpiresByType image/jpeg A2592000 ExpiresByType image/jpg A2592000 ExpiresByType text/plain A604800 ExpiresByType application/x-shockwave-flash A2592000 ExpiresByType video/x-flv A2592000 ExpiresByType application/pdf A2592000 ExpiresByType text/html A600 ExpiresByType image/x-icon A2592000 ExpiresByType application/javascript A604800 ExpiresByType text/css A604800 </IfModule>
Compress components with gzip(Gzip压缩):
About Gzip压缩
Gzip压缩是减少文件体积,增加访问速率。
操作方法:
加入代码
<ifmodule mod_deflate.c> AddOutputFilter DEFLATE html xml php js css </ifmodule>
Configure entity tags (ETags)(配置实体标签设置ETAG)
ETags(Entity tags)是服务器和浏览器的一个功能,它用来判断浏览器缓存里的元素是否和原来服务器上的一致。ETags 比 last-modified date 更具有弹性,它用一个独一无二的字符串来标识一个元素的版本。如果你不想发挥Etags提供的这个弹性验证模型的优势,你最好关掉它。
——引自:Yslow V2 规则下的优化
操作方法:
加入代码:
FileETag none
最后,总结一下上述.htaccess文件内容,大家可以参考之后自己调整自己的文件啦!
<IfModule mod_expires.c> ExpiresActive On ExpiresDefault A3600 ExpiresByType image/gif A2592000 ExpiresByType image/png A2592000 ExpiresByType image/jpeg A2592000 ExpiresByType image/jpg A2592000 ExpiresByType text/plain A604800 ExpiresByType application/x-shockwave-flash A2592000 ExpiresByType video/x-flv A2592000 ExpiresByType application/pdf A2592000 ExpiresByType text/html A600 ExpiresByType image/x-icon A2592000 ExpiresByType application/javascript A604800 ExpiresByType text/css A604800 </IfModule> <ifmodule mod_deflate.c> AddOutputFilter DEFLATE html xml php js css </ifmodule> FileETag none
号外:
Yslow评分中 Make fewer HTTP requests项是指减少http请求数,每次大爱网页都要打开服务器上的文件,而每一个文件都需要分别做一次DNS查询,建立连接,发送请求,等待回复,下载文件,总共5个步骤。如果文件过多,过散的话载入时间就会变长。解决方法就是:把CSS、JS全都合到一个文件中去,主题中尽量少的使用图片,把框架网页能去掉的都去了。
虽然这个和.htaccess文件没关系,但这个对网站的影响非常大,不容小看哦!
技术参考:加快博客访问速度——Yslow极限优化 、修改.htaccess,提升你的网站加载速度、 MIME 参考手册
所谓的晋级原来是Yslow评分
恩,ABCD的那个…现在看来也没啥意思。但的确改进了点东西
我的博文中的代码是可以拷贝的,但是你的好像不行,应该是哪一个JS没运行,重新安装下或者使用SyntaxHighlighter
嗯嗯,我搜索到了一个叫Auto SyntaxHighlighter的插件,非常简单实用,比SyntaxHighlighter单纯很多!