Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Stopping automated spam

From: WordPress 3: Developing Secure Sites

Video: Stopping automated spam

In this screencast, we use the htaccess file to prevent a type of spam known as no-referrer spam. No-referrer spam happens when spammers target the WordPress comment script directly without actually visiting your web site like a regular human being. Preventing this type of spam helps to save bandwidth and other valuable server resources and also helps keep your site looking clean and respectable to your visitors. Here in our FTP/file editor, we see the files and directories that are located in the WordPress installation directory.

Stopping automated spam

In this screencast, we use the htaccess file to prevent a type of spam known as no-referrer spam. No-referrer spam happens when spammers target the WordPress comment script directly without actually visiting your web site like a regular human being. Preventing this type of spam helps to save bandwidth and other valuable server resources and also helps keep your site looking clean and respectable to your visitors. Here in our FTP/file editor, we see the files and directories that are located in the WordPress installation directory.

To protect against no-referrer spam, we open our site's root htaccess file, which is open here already. Next, we open the htaccess code that is included with the exercise files for this screencast, and we copy the first block, Method 1. Copy that entire block and paste it beneath any existing rules in the root htaccess file. The only thing we need to edit is the fifth line, right here. We want to change example.com to match our own domain name.

Mine is perishablepress.com, so I just make that quick change and I'm all set. Next is to save the file and upload to the server. And once that's done, we return to our web site and check that everything is working properly. Pages are still loading, so everything is great. Now, let's check that the code is actually working and doing what it's supposed to do, to block no-referrer spam.

Open a browser tab and go to this extremely useful user agent simulation tool at botsvsbrowsers.com. Scroll down the page a bit and enter the URL of your WordPress installation. Next, we want to add the name of the file that spammers are trying to hit directly. To do that, return quickly to the FTP/file editor and in the root WordPress directory, you should see a file named wp-comments-post.php.

By quickly renaming the file, you can copy the name and return to the browser to simply paste it into place. Then, off to the right here, there is a dropdown menu that will set the request method, which should be set to post, because that's what the spammers will be doing. And with that, we click the Go button to make it so. Excellent! As expected, the post request returns a 403 Forbidden response, which is perfect for spammers that are trying to directly spam us using our comments post script.

Returning to our FTP/file editor, we can do a little bit more. If we would rather send our blocked request to a particular location, just replace the entire block of code with this one, also included with our exercise files. Copy Method 2 and paste into place, replacing the previous block of code. Next, with this code in place, we need to make two edits. We need to edit both instances of example.com.

The first one should be your domain name, and the second should be the URL of the location to which you want to send the blocked spammers. example.com is a reserve domain, so it's ok to use for this demo. But you should use caution when sending spammers elsewhere. Once we have our edits completed, we save the file and upload it to the server. Now, let's wrap things up by returning to botsvsbrowsers and trying to request our page again, now that the redirect method is in place.

Clicking the GO button using the same values, we see the redirect happening as expected. Here is example.com. If this were a spammer trying to spam our web site directly with no-referrer spam, this is where they'll end up. At this point, our htaccess code is in place and working great. Spammers trying to hit our comments script directly will now either be blocked using method 1, or redirected to the URL of your choice using method 2, and that's a wrap.

In this screencast, we learned how to use the htaccess file to protect our site against spam. This helps from a security perspective and from a performance perspective. No more leeching of resources means a better experience for our valued site visitors.

Show transcript

This video is part of

Image for WordPress 3: Developing Secure Sites
WordPress 3: Developing Secure Sites

36 video lessons · 11284 viewers

Jeff Starr
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed WordPress 3: Developing Secure Sites.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.