On Wednesday 29 December 2010, Andrew Farmer wrote: > 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. :)
Not what Igor wanted, but this could be simplified a lot by using the shiny new ability of RewriteCond to use ap_expr: RewriteCond %{REQUEST_URI} ^/(albums|cache)/ RewriteCond expr "%{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'" RewriteRule . - [F] BTW, is it possible to implement rewrite maps with mod_lua? I think it would be an interesting application of mod_lua if it could be used to add rewrite map functions, and ap_expr functions and operators.