Forum Moderators: phranque

Message Too Old, No Replies

Using MOD_REWRITE to redirect hotlinkers to a dynamic url

         

Go3Team

6:29 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



I am trying to redirect someone who hotlinks a file to another file such as: http://example.com/upload/store/video.avi to redirect to
http://example.com/upload/download.php?file=video.avi

I put this in an .htaccess file so that may work too but I keep coming up with:
http://www.example.com/download.php?file=/home/movie/public_html/upload/store/12.95@112.6.mpg when it should just be
http://www.example.com/download.php?file=12.95@112.6.mpg

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example.com/upload(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example.com/upload(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example.com/upload(/)?.*$ [NC]
RewriteRule .*\.(wmv¦mov¦mpg¦mpeg¦avi)$ http://www.example.com/upload/upload.php?file=%{REQUEST_FILENAME} [R,NC]

[edited by: engine at 8:29 pm (utc) on Feb. 6, 2004]
[edit reason] formatted, de-linked and examplified [/edit]

jdMorgan

4:19 am on Feb 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Go3Team,

Welcome to WebmasterWorld [webmasterworld.com]!

Try using %{REQUEST_URI} in your RewriteRule. %{REQUEST_FILENAME} is the full local server filepath to the requested resource, so I suspect that's where the extra path info is coming from.

You can also leave all that extra stuff off the end of your RewriteConds:


RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com [NC]

There will be no change in how it works, it will just run slightly faster.

Jim

Go3Team

4:36 am on Feb 7, 2004 (gmt 0)

10+ Year Member



URI works. Thanks!