Forum Moderators: phranque

Message Too Old, No Replies

.htaccess selective hotlinking of files

         

Zandaline

3:01 am on May 31, 2007 (gmt 0)

10+ Year Member



Currently I block hotlinking with .htaccess


Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(.*@)?([a-z0-9-]+\.)*MyDomain.com(:[0-9]+)?(/.*)?$ [NC]
RewriteRule .*\.(asf¦mpg¦mpeg¦wmv¦avi¦rm¦gif¦jpeg¦jpg)$ - [NC,F,L]

I would like people to be able to hotlink some files so people who syndicate my RSS feed can see the photos with the article.

All the files I would allow to be hotlinkied look like this: file-1t.jpg, file-2t.jpg etc... As you can see they all end with a number and "t". Is there a way to modify my .htaccess code to allow hotlinking of these files.

Thank you

g1smd

10:27 am on May 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Add another RewriteCond that checks that the REQUEST is NOT those (.*t.jpg$) files.

Zandaline

12:07 am on Jun 1, 2007 (gmt 0)

10+ Year Member



Thank you g1smd,

Being relatively inexperienced with .htaccess I did several searches for examples of what you mentioned but couldn't find any.

Could you or some other smart person give me an example of what the expression should look like? I have no problem researching on my own. In this situation it's been tough finding relevant info aside from your suggestion.

jdMorgan

12:30 am on Jun 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add at the top:

RewriteCond %{REQUEST_URI} !-[0-9]+t\.jpg$

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

g1smd

2:12 am on Jun 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I wasn't trying to be obscure, but JD has the answer.

This line tests the REQUEST rather than the referrer, and it has a ! in it which says to match "NOT" this.

Zandaline

5:47 am on Jun 1, 2007 (gmt 0)

10+ Year Member



Thank you very much. It worked beautifully. I appreciate the help both of you contributed. I'm off to read those articles so I don't ask any more easy questions.

g1smd

6:59 pm on Jun 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sometimes easy questions have difficult answers and vice versa!