RewriteEngine on RewriteCond %{HTTP_REFERER} !^http://flashmavi.com/.*$ [NC] Re

Discussion in 'Apache' started by martinvidic, Jul 26, 2010.

  1. #1
    Hi again.
    Got another .htaccess question
    I currently do this (see code) in order to block direct downloads and websites trying to steal my bandwidth.

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http://mydomain.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://mydomain.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.mydomain.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.mydomain.com$      [NC]
    RewriteRule .*\.(mp4)$ forbidden/forbidden.mp4 [R,NC]
    Code (markup):
    But I would like to cut down the www and non-www condition to (all non-my-domain) referrers.

    And what's more important right now, I want to set the rewrite rule so that only mp4 files from the mydomain.com/videos/mp4 folder are redirected to mydomain.com/forbidden/forbidden.mp4

    Help would be awesome :)
    Thanx
    Martin
     
    Last edited: Jul 26, 2010
    martinvidic, Jul 26, 2010 IP
  2. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You only really need one RewriteCond, just use some regex magic so the 'www' is optional.

    Something like:
    
    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mydomain\.com/ [NC]
    RewriteRule .*\.(mp4)$ forbidden/forbidden.mp4 [L,NC]
    
    Code (markup):
     
    Deacalion, Jul 26, 2010 IP
  3. martinvidic

    martinvidic Guest

    Messages:
    182
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    THAAAaaaAAAnx :)

    And if I only want to redirect the mp4's if they are in video/mp4/*.*

    Would this be right?

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mydomain\.com/video/mp4 [NC]
    RewriteRule .*\.(mp4)$ forbidden/forbidden.mp4 [L,NC]

    Thanx
    M.
     
    martinvidic, Jul 26, 2010 IP
  4. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Then you would change the RewriteRule. (the RewriteCond is just making sure the referer doesn't contains your URL)

    
    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mydomain\.com/ [NC]
    RewriteRule video/mp4/(.*)\.mp4$ forbidden/forbidden.mp4 [L,NC]
    
    Code (markup):
     
    Deacalion, Jul 26, 2010 IP