Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wanted to set up my .htaccess file so that people who hotlink my images would not be able to display may images and instead a "STEALING IS BAD" image would show up instead.

I tried to put the follwowing code into my root's .htaccess file, but it doesn't do anything. Any ideas how I'd have to modify the code any further to make it work?


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

#disable hotlinking of images with forbidden or custom image option
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)? [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)? [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)? [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ ? [NC,F,L]
#RewriteRule \.(jpg|jpeg|png|gif)$ [R,L]

# END WordPress

Thanks a lot in advance.

share|improve this question

migrated from Nov 1 '11 at 18:18

This question came from our site for WordPress developers and administrators.

This is an .htaccess question, not a WordPress development question. – Chip Bennett Nov 1 '11 at 14:59
Uhm. Sorry, I see. I didn't know about that. I'm still quite new when it comes to all this and I thought .htaccess was something unique to Wordpress. So, where would I post about it then? – japanworm Nov 1 '11 at 15:05

This here looks like you need to un-comment that in order for the image replacement to work.

#RewriteRule \.(jpg|jpeg|png|gif)$ [R,L]
share|improve this answer
Hello and thank you very much for your answer. I'm quite new to all of this, so I don't understand what you mean by "un-comment". Could you elaborate? Thank you :) – japanworm Nov 1 '11 at 23:54
Ok to un-comment that line just remove the "#" from the beginning of the line. – Nicole Nov 2 '11 at 13:54
Thank you. The code worked kind of. That means the "stop hotlinking" image is now properly showing up, however it also replaces ALL of the graphics I'm using on my website, even on the main page (index.php) although I set it as a rule that it should exclude my domain from it. Any ideas why? – japanworm Nov 2 '11 at 14:41
I am going to assume that since you are using wordpress you are using full urls to link your images (example: ). For your images inside your theme you should use /wp-content/themes/your-theme/images/yourimage.jpg . This way it should (i am not sure) not constitute as or trigger the hotlinking with in your own site. I am not sure but it is worth a shot. – Nicole Nov 3 '11 at 14:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.