Jump to content

htaccess problem


mv2

Recommended Posts

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

Link to comment
Share on other sites

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 on

RewriteCond %{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 on

RewriteCond %{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] 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.