I'd like to set up a regular expression that would disallow hotlinking of images that DO NOT end with the following pattern: -200.jpg
The "200" can actually be "150" or "250" or any number between 100-999 (that is to say 3 chars). The .jpg can be .jpeg or .png, Hotlinking of .gif is allowed.
I started with something like this:
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(.+\.)?mywebsite\.com/ [NC]
RewriteRule [^0-9]{3}\.(jpe?g|png)$ /img/hotlink.gif [NC,R,L]
For example: This should be allowed:
h*ttp://mywebsite.tld/dir/dir/hello_sdfk456er_142.jpg-200.jpg
whereas this should be denied: h*ttp://mywebsite.tld/dir/dir/hello_sdfk456er_142.jpg
But this is not working.
Also, please consider the following:
I am using url_rewriting so that the html page that displays the image is like h*ttp://mywebsite.tld/username/1337.jpg
where 1337 stands for the id of the image in the database. The reason why I'm highlighting this subtility is because a rule like:
RewriteRule ![0-9]{3}\.(jpe?g|png)$ /img/hotlink.gif [NC,R,L]
would not work.
EDIT:
I just solved it adding some exceptions:
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(.+\.)?mywebsite\.com/ [NC]
RewriteCond %{REQUEST_URI} !-[0-9]{3}\.(jpe?g|gif|png)$ [NC]
RewriteCond %{REQUEST_URI} !/[0-9]+\.(jpe?g|gif|png)$ [NC]
RewriteRule \.(jpe?g|png)$ /img/hotlink.gif [NC,R,L]
If you know a "sexier" way please let me know. Thanks anyway to the guy who gave it a try (deleted his messages?)