I have some Apache configuration like this:
# Image hotlinking rule
RewriteCond %{HTTP_REFERER} ^http://badsite\.com/
RewriteRule .*/static/artwork/.*\.(jpg|png)$ /static/images/hotlink.png [L]
# Redirects
RewriteRule ^static/artwork/(.+)$ http://cdn.mysite.com/artwork/$1 [L,R=301]
# CodeIgniter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
It should do the following:
- If a request for an image comes from
badsite.com
, block it and display the hotlink image instead. - If a regular request for an image comes in, redirect to the image hosted on the cdn subdomain.
- Otherwise, if the request is not a file or directory, load a web page page (goes through CodeIgniter).
However, I think the first RewriteCond
is applying to the redirect rule, not the hotlinking rule, because requests for images from that referrer are redirected to the CDN, not the hotlinking image. An example in the Apache docs (bottom of the section) implies that a line break stops RewriteCond
applying, but that's not happening.
Is there a way to "reset" the RewriteCond
rule, or is there some other error in my config?