Home» »How to Protect your WordPress blog from hotlinking using .htaccess

How to Protect your WordPress blog from hotlinking using .htaccess

Hotlinking is the use of images from one site into a web page belonging to other sites. Many bloggers are hotlinked, and have their bandwidth used on other websites. This code is very useful to protect your WordPress blog from hotlinking. So, this script will replace the original image with the image that we want, a warning image to appear on their blog page, where their put our image link.

This script is placed in the file. Htaccess, but to access these file you must have access to the admin panel in the hosting. This file will be exactly one level with the folder wp-admin, wp-includes, wp-content. If you do not find this file, first make sure you have show the hidden files, if the file is not exists, you can create this file directly on your hosting by click create a new file with the name ". Htaccess" without the quotes. Well here are the default script file. Htaccess, please copy and paste the file into .Htaccess file that you just created.

# BEGIN WordPress

RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]


# END WordPress

Now you have the file. Htaccess. Then the anti-hotlinking script, please copy and paste the following code into the file. Htaccess.

RewriteEngine On
#Replace ?mysite\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your "don't hotlink" image url
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

So now your .Htaccess file will be look like this.


Do not forget to replace ?mysite\.com/ with your domain name, then /images/nohotlink.jpg with your "no hotlink" image. URL address of the image is /images/xxx.jpg, so make sure you have folder "images" in there. You can make it or you can change it to another address, such /wp-content/uploads/2013/nohotlink.jpg.

That's it the tutorial of how to protect your WordPress blog from hotlinking using .htaccess, now you can try to put your image link on another blog and see what happened. Happy blogging.

About Author:

Rahman Kurnia is a blogger, SEO fighter, who loves PHP, CSS, HTML and interested in js, ajax, c++ and much more. He love writing something informatif to help others, and to keep his knowledge on the internet.

Follow him @ Twitter | Facebook | Google +

0 comments:

Post a Comment

Like us on Facebook
Follow us on Twitter
Recommend us on Google Plus
Blog Widget by LinkWithin