Saturday, April 20, 2024

利用.htaccess拒绝WordPress网站中的垃圾评论

如果你是一个WordPress用户,那么你很可能对每天大量的垃圾评论感到心烦。当然,Akismet可以阻止大部分垃圾评论,但还是有不少漏网之鱼。这里有一个小技巧,可以利用.htaccess来防止垃圾评论机器人在您的博客上放置垃圾评论。

方法很简单,只需粘贴以下代码到您网站根目录的.htaccess文件。 不要忘记在第4行指定您的博客网址。
重要提示:在编辑 .htaccess 文件前,强烈建议备份此文件。

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]

当wp-comments-post.php文件被访问时,上面的代码将查找引用者(被请求的页面地址)。如果引用者存在,并且是你的博客网址,那么这次评论是被允许的。否则,SAPM机器人将会被重定向,且评论不会被发表。

原文地址:http://www.wprecipes.com/how-to-deny-comment-posting-to-no-referrer-requests

2 comments

  1. 这个也倒是可以试一下,不知道是否管用。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.