Forum Moderators: phranque

Message Too Old, No Replies

my own site is not serving files becoz of mod_rewrite rules

mod_rewrite rules

         

telugu

6:08 pm on Nov 19, 2005 (gmt 0)

10+ Year Member



Hello all,

I am new to this forum, please help me to solve my probelm. For protecting hotlinking of my video files, i added these lines to the .htaccess file, but after that im unable to play the videos on my own site. I dont know what i am doing wrong in this, please help me to solve this issue. I am losing lot of my bandwidth because of this.

RewriteEngine On
RewriteCond %{HTTP_REFERER} [domain.net...] [OR,NC]
RewriteCond %{HTTP_REFERER} [domain.net...] [OR,NC]
RewriteRule .*.(rm¦wmv¦avi¦mp3)$ [mydomain.net...] [R,NC]

Thanks in advance for your help

larryhatch

6:14 pm on Nov 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mod rewrite rules are very unforgiving. You have to spell everything perfectly.

If you think 'becoz' replaces 'because', you are likely to have problems. -Larry

encyclo

6:18 pm on Nov 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have referers disabled (for example if you are running certain "security" products such as Norton Internet Security) then your rewrite rules will block access. You must allow for access to requests without a referer string:

RewriteCond %{HTTP_REFERER} .

jd01

7:32 pm on Nov 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Telugu,

Welcome to WebmasterWorld.

The immediate problem is the second OR in your conditions... (Not sure why there are two, they are redundant.)

Then as noted above, you should check for a blank referrer. (!=is not ¦ .(dot)=any character except the end of a line)

For efficiency, it is better to use the impicit 'everything up to' by removing the start anchor from the rule, or use a negative pattern match -- not .* if it can be avoided. (EG [^.]+ = any thing that is not a .(dot))

RewriteEngine On
RewriteCond %{HTTP_REFERER} !. [OR]
RewriteCond %{HTTP_REFERER} http://domain.net [NC]
RewriteRule ^[^.]+\.(rm¦wmv¦avi¦mp3)$ http://www.mydomain.net/cms [NC,R=301,L]

Finally, R=Undefined Redirect (302), so it is better to set the flag as either Permanent (301) OR Temporary (307) -- using the L (Last) flag will also save you some processing.

Hope this helps.

Justin

BTW An empty referrer will be redirected in the above ruleset -- to force an empty referrer to not be redirected, remove the ! and the [OR]

telugu

1:53 pm on Nov 20, 2005 (gmt 0)

10+ Year Member



Hello,

Thanks all of you for your replies,
I have norton internet security 2005 and windows firewall installed on my system.

now i changed rule like this with out HTTP_REFERER, still i am unable to see my videos on my system, may be the security programs are blocking. Please advice me if the rewrite rule is correct.
RewriteEngine On
RewriteCond %{}!. [OR]
RewriteCond %{} [domain.net...] [NC]
RewriteRule ^[^.]+\.(rm¦wmv¦avi¦mp3)$ [mydomain.net...] [NC,R=301,L]

Thanks for your help

jdMorgan

5:21 pm on Nov 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is "cms" used for?

Jim

telugu

6:36 pm on Nov 20, 2005 (gmt 0)

10+ Year Member



What is "cms" used for?

my site is in this folder

Thanks

jdMorgan

7:22 pm on Nov 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you will take the time to explain how this is supposed to work, we may be able to help. Either that, or it will take days for us to figure out what you are trying to do, and guess at an answer.

The last code you posted is invalid, and I'm surprised you did not get a 500-Server Error when it was invoked.

*IF* a request is redirected to /cms/, how does /cms/ know what content to serve? Is this a script that examines the client request header to get the originally-requested filename, or what?

If the request is *not* referred from your own site(s), what do you expect to happen?

Jim

telugu

10:29 am on Nov 21, 2005 (gmt 0)

10+ Year Member



Hello,

sorry for my english and my poor explanation.

I have some video files on my website for my users. When i checked my log files i found that in some public forums people posted links to these files, so that visitors of that sites can download directly with out knowing that they are doxnloadinf from my site and they will not come to my site.

I want to prevent this, in google i found mod rewrite rules from this site [modwest.com...]
i added these lines to my .htaccess file. I dont know anything about these rules and how they will work.

RewriteEngine On
RewriteCond %{HTTP_REFERER} [domain.net...] [OR,NC]
RewriteCond %{HTTP_REFERER} [domain.net...] [OR,NC]
RewriteRule .*.(rm¦wmv¦avi¦mp3)$ [mydomain.net...] [R,NC]

But after this iam unable to see these videos on my own site; iam getting errors.

Now i want to write a rule so that users from my site will be able to see the files and if somebody from other sites refer to these they should get an error message or they should be redirected to my home page.

I am using xoops cms 2.2.3 and i installed it in /cms folder

I hope i am clear now, if anything missing please let me know.

Thanks in advance for your time.

[edited by: jdMorgan at 2:27 pm (utc) on Nov. 21, 2005]
[edit reason] No URLs, please. See TOS. [/edit]

jdMorgan

3:57 pm on Nov 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, I assume that the CMS is the 'agent' that serves videos to authorized users only.

If so, then the only problem I see is that you have an [OR] flag on your second RewriteCond. This is a logical error and a syntax error, since only RewriteConds can be ORed.

So try this first:


RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?domain\.net [b][NC,OR][/b]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?domain2\.net [b][NC][/b]
RewriteRule \.(rm¦wmv¦avi¦mp3)$ http://www.domain.net/cms [R,NC]

If that works properly, then change it to do a 'silent' internal rewrite, so that you do not 'expose' your cms URL to view:

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?domain\.net [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?domain2\.net [NC]
RewriteRule \.(rm¦wmv¦avi¦mp3)$ /cms [NC]

Change all broken pipe "¦" characters above to solid pipes before use; Posting on this board modifies them.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

telugu

6:30 pm on Nov 22, 2005 (gmt 0)

10+ Year Member



Hello,

Thanks alot, everything is working now.
Many many thanks for your time.