How to Disable Image Hotlinking in WordPress Using .htaccess File

How to Disable Image Hotlinking in WordPress Using .htaccess File

Hotlinking is the process of sharing an image by directly linking to your website which increases the load on your server and downgrade performance of your website. It is very easy to find out if someone hotlinked your image. Head over to Google image search use search query inurl:yoursite.com -site:yoursite.com replace yoursite.com with your website URL. You will see which website use image of your website and images get served from your server.

How to Disable Image Hotlinking in WordPress Using .htaccess File-:

If some hotlinked your website image which means You can prevent the hotlinking by adding this code snippet to your WordPress .htaccess file: before editing .htaccess file take its backup. you can access your .htaccess file using hosting cPanel or FTP client. For more info, you can read my post How to use Filezilla FTP client with your WordPress Hosting. If you’re hosting one website on your server, it’s more likely you can find the data in the public_html/root directory.

To Prevent Image Hotlinking add following code to .htaccess file.

RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourwebsite.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourotherwebsite.com [NC] 
RewriteRule \.(jpg|jpeg|png|gif)$ http://i.imgur.com/g7ptdBB.png [NC,R,L]

Your .htaccess File will look like as Follow-:

# BEGIN WordPress
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourwebsite.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourotherwebsite.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://i.imgur.com/g7ptdBB.png [NC,R,L]

After adding you have to add the website which you want to allow.

How to Disable Image Hotlinking in WordPress Using .htaccess File

If you like my work, Please Share on Social Media! You can Follow WP knol on FacebookTwitterPinterest and YouTube for latest updates. You may Subscribe to WP Knol Newsletter to get latest updates via Email. You May also Continue Reading my Recent Posts Which Might Interest You.

About Amar Patel 263 Articles
Hi, I am Amar Patel from India. Founder, Author and Administrator of wpknol.com. I am a Simple Average Man who Loves life and Love living life.Professionally I am a Mechanical Engineer. Apart from my Job, I Love to write the things around WordPress WordPress CMS.