nuxx.net
Making, baking, and (un-)breaking things in Southeast Michigan.

Help!

Could someone who’s familiar with Apache’s mod_rewrite and regexp help me understand what’s wrong with the following statements?

# Slashdot video…
RewriteCond %{HTTP_REFERER} ^http://*slashdot* [NC]
RewriteCond %{REQUEST_FILENAME} /files/videos/bull_512k.mov [NC]
RewriteRule ^$ /files/videos/sorry_slashdot.mov [R=301,L]

I know I’m doing something wrong, but I’m not sure what…

Thank you. :)

5 Responses

  1. arcsine March 21, 2005

    Waitaminute… You got Slashdotted? Ouch.

    1. c0nsumer March 21, 2005

      No, a 1.8MB video I host is linked directly from Warren Ellis’ blog. I consider it a precursor to Slashdotting, because the video is especially funny.

      1. arcsine March 21, 2005

        Ahh, pre-emptive Slashdot denial measures. I saw the Warren Ellis thing, I imagine he found it on his /friendsfriends ([info]batwinged has him on her list.

  2. mod_rewrite uses regular expressions

    Your match condition is slightly off — “*” is not a wildcard but a “zero or more” modifier for regular expressions. Make your first line:

    RewriteCond %{HTTP_REFERER} ^http://(www\.)?slashdot.* [NC]

    Note replacing * with .* (zero or more of any non-newline), and since the wildcard matcher is greedy, getting more specific before “slashdot”.

    Also (you may already know this), checking the referrer doesn’t qork all that often; it’s only supplied when the person clicks a link on the originating page (cutting and pasting the URL into a browser will go to your site w/o setting the referrer.)

    1. c0nsumer March 28, 2005

      Re: mod_rewrite uses regular expressions

      Thank you. My regexp is really bad. :\

      And yeah, I knew the second part… I was just somewhat anticipating /. submissions of the movie itself, and I wouldn’t want the direct link of people clicking right on it.

      Thanks for helping me straighten that out… I’ll toss it in tomorrow when I’m doing more server work.

Leave a reply