Forum Moderators: phranque

Message Too Old, No Replies

Local Access to PDF

Preventing offsite linking to pdfs

         

varya

7:48 pm on May 11, 2004 (gmt 0)

10+ Year Member



I've searched the net, and the archives here, and I haven't been able to find exactly what I need.

How can I restrict access to pdfs so they can only be accessed through a page on my site?

I'd like to redirect offsite incoming links to the nav page for the pdfs.

They are all in one directory together (about 30 files).

Thanks.

john_k

7:54 pm on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The answer will vary depending upon your server. I would ask this question in either the PHP or ASP forum.

TheDoctor

8:13 pm on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your server uses Apache, ask in that forum. You use .htaccess to achieve what you want.

ergophobe

8:20 pm on May 11, 2004 (gmt 0)

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



[edit]
TheDoctor posted while I was writing this, but he adds two useful items
- yes this goes in .htaccess
- yes, the folks on the Apache forum know this stuff cold and if my rewrite doesn't work, go there for help
[/edit]
Are you on Apache? You could try to use mod_rewrite.

Warning: I have not tested this. There may be errors in logic or typos, but it should give you the idea.

RewriteEngine On
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mysite.com(/)?.*$ [NC]
RewriteRule .*\.pdf$ [mysite.com...] [R]

These lines, in order mean

1. RewriteEngine On

Turn on the rewrite engine (go figure)

2. RewriteCond %{HTTP_REFERER}!^$

If there's is a referrer (that is referrer is *not* nothing). This means if the user has not just typed in a URi or used a bookmark.

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

If the referring site is *not* mysite.com (or www.mysite.com, or MySite.com - NC makes the condition case insensitive).

4. RewriteRule .*\.pdf$ [mysite.com...] [R]

If one of the above conditions has been met, apply the rule, which says that any pdf should be rewritten as a redirect to the pdf index.

Note, if *you* have domains other than www.site.com and site.com, you can also negate them in the rewrite conditions.

varya

10:42 pm on May 11, 2004 (gmt 0)

10+ Year Member



Thanks, ergophobe, I'll try that.

I meant to say that I'm on Apache and that I was looking for an htaccess solution when I posted, but left that info out somehow.