wordpress应用之htaccess

1.实现wordpress防盗链

直接放个.htaccess文件到uploads目录下,参考了网上若干.htaccess的写法,最后我的版本如下:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !magustest.com [NC]
RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC]
RewriteCond %{HTTP_REFERER} !xianguo.com [NC]
RewriteCond %{HTTP_REFERER} !google.com [NC]
RewriteCond %{HTTP_REFERER} !google.cn [NC]
RewriteCond %{HTTP_REFERER} !feedburner.com [NC]
RewriteCond %{HTTP_REFERER} !feedsky.com [NC]
RewriteCond %{HTTP_REFERER} !testingjob.net [NC]
RewriteRule .*.(jpg|gif|png|bmp|swf|jpeg)$ xxx/forbid.png [R,NC,L]

RewriteCond 里面的第一行是说如果没有Referer,也就是直接访问,那么可以看。接下来的就是白名单,其中允许了谷歌,抓虾,鲜果等网站,那么在这些网站里面订阅我的博客的朋友也都能看到图片了。最后一行RewriteRule就是如果后缀名是那6个(都是吃流量的多媒体文件)的话,那么就显示为xxx/temp/forbid.png这个图片。

一般Linux类和Unix类虚机主机都支持重写.htaccess。这样子设置以后,在常见的阅读器中查看博客文章也能看到图片,同时也能有效地防止盗链图片而导致的流量超标。

2.压缩静态数据

以下.htaccess代码节约了你(以及你的访问者)的带宽,减轻了博客页面的压力。

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css 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

3.禁止机器人评论

事实证明,很多垃圾评论机器人无处不在。 下列代码会追踪评论的来源(评论者所在的页面),如果评论者试图不经你的博客擅自进入wp-comments-post.php文件,这些代码会禁止评论发布。更改第四行命令,换成自己博客的url。

RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post.php*
RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

4.

2 comments to wordpress应用之htaccess

Leave a Reply to Roman Url

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Protected by WP Anti Spam