Home » Wordpress 技巧

通过.htaccess文件来屏蔽垃圾评论

这篇文章翻译自problogger.net的 Banishing Spammers and Trolls With .htaccess Files

如果你的博客有一定的知名度或者PR比较高的话,那么你的博客肯定会被很多的垃圾评论所困扰。这篇文章将向你介绍如何通过设置wordpress博客的.htaccess文件来屏蔽垃圾评论。这种方法的关键就是通过屏蔽发布垃圾评论人的 IP 地址来达到屏蔽垃圾评论的目的。

这篇文章主要介绍的方法主要是适用于通过wordpress建立的博客的,但如果你的服务器也有 .htaccess 文件,那么你不防也可以在其他的博客平台上试试。

什么是 .htaccess 文件?

.htacess 文件就是空间服务器中允许你对你博客的访问者设置一定的规则的配置文件。通常可以搭建 WordPress的空间中我们都可以找到该文件。更多关于.htacess 文件的信息,可以看百度百科

这里介绍的方法就是通过检测到IP 地址,然后限定该地址的访问。

找到发表垃圾评论的IP地址

在WordPress的后台我们可以清楚地看到每一位发表评论者的IP 地址。如果你用的是最新的wordpress版本(2.71),那么进入到后台后,你就可以清楚地看见评论者的IP 地址,邮箱,评论内容等,这样你也很容易就可以鉴定哪些是垃圾评论。

修改 .htacess 文件

在修改 .htaccess 文件之前要注意的一点就是如果你在修改的过程犯了任何错误都有可能使你的整个博客瘫痪。所以,在修改之前我们要对.htaccess 文件进行备份。通常情况下我比较喜欢将.htaccess 文件下载到本地,然后将它复制一份,然后修改原文件,修改完之后再将它上传到服务器。

默认的 .htaccess 文件

在 WordPress平台中的 .htaccess 文件默认如下:

# BEGIN WordPress

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

</IfModule>

# END WordPress

我们可以看到默认的文件中只有很少的规则。

需要添加的内容

把下面的代码复制到 .htaccess 文件中 #END WordPress section 代码的后面,然后将你要屏蔽的ip地址放进并取代 {} 中的内容。

order allow,deny

deny from {IP ADDRESS}

deny from {SECOND IP ADDRESS ONE PER LINE}

deny from {YOU CAN ALSO USE DOMAIN NAME trollhostname.com}

allow from all

# END spammers and trolls

你可以通过文本来编辑 .htaccess 文件,将你要屏蔽的ip地址写上去后,就把你编辑好的文件上传到服务器代替掉原来的 .htaccess 文件。

进行测试

如何在上面添加的 IP 地址都不可以再访问你的博客,当他打开你的博客时看到的将是  403 forbidden的信息,具体内容如下:

Forbidden

You don’t have permission to access / on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

你可以通过在 .htaccess 文件中添加你自己的ip地址测试一下。不过记得测试之后要把它从.htaccess 文件删掉,要不然你就不可以访问自己的博客了^^

今天的技巧就写到这里了,如果你有什么其他的技巧或者插件可以实现类似功能或者可以屏蔽垃圾评论的,不放分享一下。

Popularity: 1% [?]

Share/Bookmark this!

One Comment

Leave a reply

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally recognized avatar, please register at Gravatar.

Side Notes

This entry was posted by 莫 涯 on May 29, 2009 at 9:12 pm and filed under Wordpress 技巧 category.

You can add your comments or trackback from your own site. To keep you updated to the latest discussion, you can subscribe to these comments via RSS.

This is a Gravatar-enabled weblog. To get your own globally recognized avatar, please register at Gravatar.

最新文章

最新评论

Tag Cloud

301 Redirect 301重定向 2010 about All in one seo pack AutosCraze blog CSS Darren feed FreshMag Global Translator Google GreenFun HTML Insider name.com Problogger robots.txt文件 RSS Feed seo Wordpress Wordpress 主题 Wordpress主题 代码 优惠码 关于 博客 博客建设 域名 工具 建设 技巧 提交 插件 文章 杂志型主题 标签 注册 绿色 网赚 评论 选择 链接 页面