mv2 Posted December 30, 2003 Share Posted December 30, 2003 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 Quote Link to comment https://forums.phpfreaks.com/topic/1581-htaccess-problem/ Share on other sites More sharing options...
gizmola Posted December 30, 2003 Share Posted December 30, 2003 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] Quote Link to comment https://forums.phpfreaks.com/topic/1581-htaccess-problem/#findComment-5179 Share on other sites More sharing options...
mv2 Posted December 30, 2003 Author Share Posted December 30, 2003 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 Quote Link to comment https://forums.phpfreaks.com/topic/1581-htaccess-problem/#findComment-5188 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.