When someone accesses example.pdf they get redirected to viewer.php. viewer.php should be able to access the pdf file. However, the .htaccess file causes the viewer.php file to not be able to access the pdf because of the redirect and gets caught in a loop.
Is there a way to add the following logic to .htaccess:
if(host = myserver)
do not redirect pdf
else
redirect pdf to viewer.php
thanks
Here is my htacces file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+)\.pdf$ web/viewer.php?pdf=$1 [L,NC,QSA]
AddType application/octet-stream .pdf
Edit: I've taken a look at the libraries source and it isn't your server making the request to the PDF, it's the javascript which will be a client side request unfortunately and therefore this won't be as easy as I think you were hoping for! (Ie you can't just check for 127.0.0.1 as it will be users' IP addresses).
I'm not sure how it would work properly, but one option could be to update all of the PDF files adding an extra character to the file extension (so instead of .pdf it's .pdfs or similar). You could then update your RewriteRule adding an "s" after the $1 like so:
RewriteRule ^(.+)\.pdf$ web/viewer.php?pdf=$1s [L,NC,QSA]
This is assuming that the pdf.js script is able to render files without the extension .pdf.
Try something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REMOTE_ADDR} !^127.0.0.1$
RewriteRule ^(.+)\.pdf$ web/viewer.php?pdf=$1 [L,NC,QSA]
AddType application/octet-stream .pdf