Jump to content


Photo

htaccess problem


  • Please log in to reply
2 replies to this topic

#1 mv2

mv2
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 30 December 2003 - 06:02 AM

Hello,

I have searched the boards and couldn\'t find an answer that seemed to solve my problem. I am using .htaccess to prevent hotlinking to my site and it is working very well. The only trouble I am having is that requests for files written in the http://domain.com/files.ext format somehow get past my htaccess file whereas http://www.domain.com/files.ext are caught and redirected. Here is a copy of the rewrite code I am using. Any help on this is greatly appreciated.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://domain.(.*)/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.*).domain.(.*)/.*$ [NC]
RewriteRule (.*.(gif|jpg|avi|mpg|mp3|wmv|wma|rm)$) http://domain.com/hotlinking.php [R,NC]

thank you,

Chris

#2 gizmola

gizmola
  • Administrators
  • Advanced Member
  • 4,664 posts
  • LocationLos Angeles, CA USA

Posted 30 December 2003 - 07:24 AM

Well the problem as I understand it is that your RewriteCond\'s are Ands. So i

If 1st condition AND 2nd Condition And 3rd Condition. Hence when you have will not work, because while the http://domain.etc does match the first regex, it will not match the 2nd, and so it falls through.

Anything to do with mod_rewrite is tricky, but I\'d question why you are trying to make two different rules when one can satisfy both conditions. On the other hand, simply adding the OR to your Flags might work. If you want to try my swag at having only one rule:

RewriteEngine onRewriteCond %{HTTP_REFERER} !^$RewriteCond %{HTTP_REFERER} !^http://(.*.|)domain.(.*)/.*$ [NC]RewriteRule (.*.(gif|jpg|avi|mpg|mp3|wmv|wma|rm)$) http://domain.com/hotlinking.php [R,NC]

For your existing rule, it\'s certainly worth trying this first however:

RewriteEngine onRewriteCond %{HTTP_REFERER} !^$RewriteCond %{HTTP_REFERER} !^http://domain.(.*)/.*$ [NC,OR]RewriteCond %{HTTP_REFERER} !^http://(.*).domain.(.*)/.*$ [NC]RewriteRule (.*.(gif|jpg|avi|mpg|mp3|wmv|wma|rm)$) http://domain.com/hotlinking.php [R,NC]


#3 mv2

mv2
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 30 December 2003 - 07:52 PM

gizmola,

Thank you for the reply. I will try adding the or condition to my code to see if it works. To answer your question, I only posted a snippet of my actuall rewrite conditions. I run a music distribution site for artists much like mp3.com and deeplinking to their content is offered as part of the subscription services. What I am trying to do and have been successfull in part is keeping everyone else from being able to link directly to the media files on the site. For a music site, this is a huge concern as I usually use about 20 gigs of bandwidth a day and have only been open 7 months. Anyway, thank you for your answer. I will give it a try and post back here.

Chris
www.musicv2.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users