On 29 Dec 2010 at 01:25, Igor Galić wrote: > Please share your particularly ugly, involved, unaesthetic or > otherwise /wrong/ solutions done with mod_rewrite because it > was the only hammer available for the screws at that time ;)
I came up with the following abomination a while back to disable hotlinking to files when the referrer doesn't match the request host (in conjunction with a setup that amounts to wildcard DNS): > RewriteEngine on > RewriteCond %{HTTP_REFERER} ://([^/]+)/ > RewriteRule . - [E=RHOST:%1] > > RewriteCond %{REQUEST_URI} ^/(albums|cache)/ > RewriteCond %{ENV:RHOST} !^$ > RewriteCond %{HTTP_HOST}:%{ENV:RHOST} !^([^:]*):(\1)$ > RewriteRule . - [F] The observant will notice a novel abuse of regex backreferences used here to implement string comparison. A reimplementation of the same configuration in Lua should be able to avoid this. :)