Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: deny direct file download with pdf viewer |
|
Author |
|
Davide Zanon
Joined: 23 May 2016 Posts: 2
|
Posted: Mon 23 May '16 14:28 Post subject: deny direct file download with pdf viewer |
|
|
Hi everybody,
I integrated ViewerJS as pdf viewer in my company site and it works fine, now what I'm trying to do is to prevent users from downloading those pdf files,
for example with the built-in download button in the viewer or using full file path from page source.
In the pdf directory I tried setting an .htaccess file like this:
Code: |
RewriteEngine On
RewriteCond %{REQUEST_URI} \.(pdf)$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com [L]
|
Which works far too well because now the viewer doesn't show pdfs anymore.
Any help would be appreciated.
Thanks |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Tue 24 May '16 20:58 Post subject: |
|
|
You need to exclude the pdf path from the main url rewriting from the vhost. That doesn't work in the subdirectory
e.g.
Code: | RewriteEngine on
# exclude paths and and single file
RewriteRule ^(content_images|design_images|css|js|media|lib|index\.php) - [L]
RewriteCond %{REQUEST_URI} !^/dispatch.php(.*)$
RewriteRule ^(.*)$ dispatch.php/$1 [L] |
|
|
Back to top |
|
Davide Zanon
Joined: 23 May 2016 Posts: 2
|
Posted: Wed 25 May '16 12:06 Post subject: |
|
|
Hi James, thanks for your reply.
So you're suggesting that I should put the code inside the vhost config file (under sites-available/enabled), right?
In my case it would look like this:
Code: |
RewriteEngine on
RewriteRule ^(mydocument\.pdf) - [L]
RewriteCond %{REQUEST_URI} !^/subdir/withpdf/mydocument.pdf(.*)$
RewriteRule ^(.*)$ ViewerJS/#/$1 [L]
|
Correct me if I'm wrong before I screw something up (the "ViewerJS/#/" part is how the viewer loads the document in the page).
Would it be ok to put "*.pdf" for all pdf files? I'm totally new to Apache so please be patient.
Thanks |
|
Back to top |
|
|
|
|
|
|