.htaccess是一个非常强大的分布式配置文件,学会使用.htaccess,对网站用户来说,可以实现众多的功能。这里我们可以罗列一下通过修改.htaccess文件来增强网站的功能的一些有用实例。
feed的重定向设置:
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds2.zl5.info/xxx [R=302,NC,L]在wordpress的url中去除/category/
RewriteRule ^category/(.+)$ http://www.zl5.info/$1 [R=301,L]使用浏览器缓存加速wordpress访问速度
FileETag MTime SizeExpiresActive on
ExpiresDefault "access plus 1 year"开启gzip压缩
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascriptBrowserMatch ^Mozilla/4 gzip-only-text/htmlBrowserMatch ^Mozilla/4.0[678] no-gzipBrowserMatch bMSIE !no-gzip !gzip-only-text/html 把带有日期格式的永久链接形式重定向到/%postname%/格式RedirectMatch 301 /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://www.zl5.info/$4
阻止没有referrer requests的评论减少垃圾评论
RewriteEngine OnRewriteCond %{REQUEST_METHOD} POSTRewriteCond %{REQUEST_URI} .wp-comments-post.php*RewriteCond %{HTTP_REFERER} !.*zl5.info.* [OR]RewriteCond %{HTTP_USER_AGENT} ^$RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]重定向访客到维护页面
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$RewriteCond %{REMOTE_ADDR} !^123.123.123.123RewriteRule $ /maintenance.html [R=302,L]保护您的博客不被盗链
RewriteEngine On#Replace ?xxx.com/ with your blog urlRewriteCond %{HTTP_REFERER} !^http://(.+.)?xxx.com/ [NC]RewriteCond %{HTTP_REFERER} !^$#Replace /images/nohotlink.jpg with your "don't hotlink" image urlRewriteRule .*.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]只允许固定的ip地址访问wp-admin
AuthUserFile /dev/nullAuthGroupFile /dev/nullAuthName "Example Access Control"AuthType Basicorder deny,allow
deny from all allow from xxx.xxx.xxx.xxx屏蔽固定ip访问
order allow,deny deny from xxx.xxx.xxx.xxx allow from all