Alden Bates (abates) wrote,
Alden Bates
abates

.htaccess Rewrite Engine gotcha

I've been wondering why my 403 (access denied) scripts for my music and NZDWFC subdomains on my site weren't working. They log all hits from sites attempting to hotlink to my graphics - a while back I inserted some mod_rewrite voodoo into the .htacces file on tetrap.com to prevent all hotlinking, including on the domains.

I decided to try an experiment - I banned my own IP and tried to access the NZDWFC site. I got a 403 error, and the 403 script logged the error properly, so the scripts were OK.

I then tested the hotlinking by translating a page in Google. The graphics loaded. The image hotlinking protection on the two subdomains was broken. Buggery.

It turned out to be because I'd added mod_rewrite blocks to the .htaccess files for the subdomains, in order to redirect www.music.tetrap.com to the shorter music.tetrap.com. Apparently these rewrite blocks overrode the one in the .htaccess file for the domain as a whole, and that's where the voodoo for banning hotlinks was located. Fixing it was a matter of copying the appropriate hotlink prevention lines into the .htaccess files on both subdomains.

I now anticipate a flood of failed hotlink attempts, as no doubt people have been linking to album covers like mad.
Subscribe

  • Hi Livejournal

    Long time, no write. I hope everyone is keeping safe from the pandemic and not going out much. I started working from home earlier this week when…

  • Wait

    What happened to my friends page? Clearly I have been away from LJ too long and they have changed things. Look, I'm a big subscriber to the idea…

  • I've been playing Fallout 3 a bunch recently

    I'm playing it as an evil character because I already did a good playthrough. Reminds me of someone...

  • Post a new comment

    Error

    Comments allowed for friends only

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments