0

i want to allow some files to be downloaded if only the user agent or referrer match the following

These are the user agents uTorrent Bittorrent Transmission

This is the http referrer www.niresh12495.com

I'm trying the following code but shows Error 500

RewriteCond %{HTTP_USER_AGENT} !^(*uTorrent*|*BitTorrent*|*Transmission*) [NC,OR]
RewriteCond %{HTTP_REFERER} !^http://niresh12495.com/.*$      [NC,OR]
RewriteCond %{HTTP_REFERER} !^http://niresh12495.com$ [NC,OR]
RewriteCond %{HTTP_REFERER} !^http://www.niresh12495.com/.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} !^http://www.niresh12495.com$  [NC,OR]
RewriteRule ^*\.(dmg|torrent|pkg|rar|exe|zip|jpeg|jpg|gif|png|bmp|mp3|flv|swf|png|css|pdf|mpg|mp4|mov|wav|wmv|swf|css|js|iso)$ http://www.niresh12495.com [R,F,NC]

Where am i wrong ?

Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
Niresh
  • 103
  • 4

1 Answers1

0

There are multiple problems.

  1. There are syntax errors in your regular expressions. You're using * like a shell wildcard character, but in regexes it has a different meaning: it only modifies another character, to mean "0 or more occurrences of". What you probably want is .*, meaning "0 or more occurrence of any character". But you don't even need that, if you remove the start anchor tag ^.

  2. Your last RewriteCond ends with an OR flag, which is probably invalid since no other RewriteCond follows it.

  3. I think your conditional logic is wrong. You currently have

not (uTorrent or BitTorrent or Transmission) OR not niresh12495.com OR not www,.niresh12495.com

but I think you want

not (uTorrent or BitTorrent or Transmission) AND not niresh12495.com AND not www.niresh12495.com

So I think you want something more like this:

RewriteCond %{HTTP_USER_AGENT} !(uTorrent|BitTorrent|Transmission) [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.|)niresh12495.com(/|$) [NC]
RewriteRule .*\.(dmg|torrent|pkg|rar|exe|zip|jpeg|jpg|gif|png|bmp|mp3|flv|swf|png|css|pdf|mpg|mp4|mov|wav|wmv|swf|css|js|iso)$ http://www.niresh12495.com [R,F,NC]
Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
  • hi @andrew-schulman thanks for the answer but the problem is user agents they actually vary uTorrent/12345 BitTorrent/1462 Transmission/SomeNumericValue How can i solve this ? – Niresh Mar 07 '14 at 16:46
  • The expression `(uTorrent|BitTorrent|Transmission)` isn't anchored, so it matches any of the strings uTorrent, BitTorrent, or Transmission if they appear anywhere in the string. So it matches any of the cases you mentioned. – Andrew Schulman Mar 07 '14 at 17:07