.htaccess category archive

Enable image hotlinking from LiveJournal subdomains

February 9th, 2006 | Filed under Apache web server, mod_rewrite, .htaccess

A friend of mine disables image hotlinking from her site using mod_rewrite, but she also syndicates her weblog to LiveJournal, so she allowed livejournal.com to hotlink with her .htaccess file, like this:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?livejournal.com.*$ [NC]
RewriteRule \.(jpe?g|gif|bmp|png)$ images/stealingbandwidth.gif [L]

But recently LJ changed their URL scheme to subdomains, so all her friends were seeing her “You’re stealing bandwidth!” image when they read her journal from username.livejournal.com.

So, we modified her .htacess mod_rewrite rule to:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://([a-zA-Z0-9_]+\.)?livejournal.com.*$ [NC]
RewriteRule \.(jpe?g|gif|bmp|png)$ images/stealingbandwidth.gif [L]

And in the process I was once again reminded how the simplest of regex’s can still completely kick my ass.