This short snippet will help you block images from Google, other search engines, and the general public. Your images will be able to be included on your website pages, however they won’t be accessible directly (ie via www.yourdomain.com/image.jpg, for example), won’t be accessible by Google and other search engines, and won’t be accessible by any other websites.
The Code
Add the following to your htaccess file:
1 2 3 4 |
RewriteEngine on RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain [NC] RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.*$ [NC] RewriteRule \.(gif|jpg|png)$ - [F] |
You would change “yourdomain” to whatever your domain name is. The code above will show a 404 error page when image URLs are accessed directly. Also note that you should clear your browser cache before testing to see if this works.
FYI if you are looking for an easy way to block access to your WordPress site, a way that doesn’t require you messing around with the htaccess file, you can check out my Hide My Site WordPress plugin.
Thanks for taking the time to follow this tutorial. Hope you find it helpful. Please let me know if you have any questions or other feedback in the comments.