IWD Designed Get Firefox!

This is a Britblog
This is an English Britblog

Some things I agree with
(or not as the case may be)

EFF: No Broadcast Flag No Watermarks

Monday, March 1
One EXTREMELY handy piece of .htaccess code

I was trying to find a way to redirect users _TRANSPARENTLY_ via .htaccess (there was a big DJ mix that somebody did, and they were hosting it on one of their sites, which only (only!) has 10gb/month of bandwidth allowance. They also have another account, which is on the host's Premium package - and has about 50gb of bandwidth a month.

I didn't want to tell the person who owns both domains that they should just "upgrade the first account", as they've already upgraded it once, and it'd just cost too much to be paying for a Premium package for both.


So... I set about finding a way to redirect users via .htaccess JUST FOR ONE FILE (not an entire directory, like you can do with Apache's mod_rewrite).

And I patched together a way to do it. Yes, I know it's not the most advanced thing that many web designers will have seen, but it works and works well for what it was designed to do. I actually pinched the idea from another .htaccess image remote link disallowing script I wrote earlier this month :)


Here's the code... Replace the filename with the filename for your purpose, if you want to use it. Obviously, logic dictates what you should change to fit your situation.


{code begins}

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^//(www\.)?#sitewithnotmuchbandwidth.tld/optional_subfolder/.*$ [NC]
RewriteRule .*\.(mp3|MP3)$ //sitewithloadsofbandwidth.tld/optional_subfolder/actualfile.mp3 [R,NC]

{code ends}

Obviously, this isn't for the faint of heart - only people who consider themselves confident webadmins should use this code, as .htaccess modification itself isn't for the faint of heart (cause quite often if you muck something up, there's no instructions on what's gone wrong... or how to fix it ;).

AND, to add to that, I'm sure there's a much simpler (and tidier) way of doing this - but it achieves the aim I was after. Saving bandwidth (and therefore stopping the ability to access the site from the web, because the host stops access for the rest of the month if the allotted bandwidth is exceeded).

:) (Geek bit over).


On the other hand, guess who forgot to change his watch's date to the 29th of February yesterday... I was living in March the 1st for an extra day :) (looks embarassed) =D


Dragged out of Christopher's memory and pasted
into his blog at 3/01/2004 02:10:00 AM. Roughly.
Blog ID: 107810705759905531·
| Permalink



Links!
Mobile/low-bandwidth version
 

Back the Bid at london2012.com  
The Internet is Shit. Pure genius!
Get Skype! Free VoIP goodness.

Link to me:
Kerblam! by Christopher.
Kerblam! by Christopher.




Blogroll...



Top UK Blogs
Top of the British Blogs