How to block websites

2. Blocking Websites In Your .htaccess File

If you want to block these sites from accessing your blog entirely, like forever and eternity, then follow the steps below VERY CAREFULLY!

Warning and disclaimer: The following step involves blocking websites in your .htaccess file. If you’re not comfortable with proceeding with this process yourself, please consider hiring a developer to do it for you.

Blocking via .htaccess is by far the best method for preventing those sites from appearing in your GA reports, and, using up your valuable server resources.

Backup First: Before you start, please make sure you’ve made a backup copy of your .htaccess file first, before making any changes or modifications. This is critically important.

When ever I need to make changes to my .htaccess file, I simply copy the entire contents of the file and paste it into a new txt file to save on my computer. At least then, if I make a mistake and accidentally take down my whole website, I can revert back to the original file via cPanel access.

OK troopers, let’s begin.

Step One: Find and access your .htaccess file

Find and access your .htaccess file!

If by any chance you’re using Bluehost web hosting, log into your hosting account as normal, then head over to cPanel > File Manager (under file management).

In file management, double click on the website name you want to access the .htaccess file for.

Now click on the .htaccess file itself and click “Edit”.

A pop-up box should appear telling you what you’re about to edit.

Hit the Edit button and a new tab should appear. You’re now in your .htaccess file, editing mode.

Related text  How to get rid of drain flies

Enter with great care. See image below.

Access Block 1

Accessing your .htaccess file via other hosting providers should be relatively similar if a cPanel is provided.

SiteGround web hosting, also offer an identical cPanel like this.

Step Two: Paste the ‘blocking code’ below

Once again, make sure you have made a backup copy of all the contents in your .htaccess file.

Now copy and paste the following code in the bottom of your .htaccess file page:# block visitors referred from these spam websites RewriteEngine on RewriteCond %{HTTP_REFERER} [NC] RewriteCond %{HTTP_REFERER} [NC] RewriteCond %{HTTP_REFERER} [NC] RewriteCond %{HTTP_REFERER} [NC] RewriteCond %{HTTP_REFERER} [NC] RewriteCond %{HTTP_REFERER} [NC] RewriteCond %{HTTP_REFERER} [NC] RewriteCond %{HTTP_REFERER} [NC] RewriteCond %{HTTP_REFERER} [NC]

RewriteRule .* – [F]

For your convenience, I’ve added the websites I mentioned at the start of this post to the list.

If you want to add a new condition (website to block), simply copy and paste:RewriteCond %{HTTP_REFERER} [NC]And add it before the:

RewriteRule .* – [F]

Don’t forget to change the part that says with the URL you want to block.

Like this post? Please share to your friends: