|
HTML Password Lock is file
based, basically it can only protect web pages, including HTML,
ASP and PHP pages. But with some techniques, we can use it to
protect Adobe PDF, Microsoft Word, Excel, Powerpoint and image
files. This tutorial will take PDF file as an example.
There are two steps to protect PDF files on your web server
with HTML Password Lock.:
Protect
the web page which has links to these files. It's very easy
to password protect web pages with HTML Password Lock, please
refer to http://www.mtopsoft.com/htmllock/help.htm
for how to do that.
If you
are using an Apache web server (90% of web servers on Internet
are Apache based), we can use .htaccess file to limit the access
of PDF files:
- If visitors access the PDF file from the locked web page,
that is, if he logs in the locked web page, then clicks link
on the web page, downloads or views the PDF file, everything
will be fine.
- If he directly enters the URL web address of PDF file in
his web browser, or bookmarked the address of PDF file, and
then try to open the bookmarked address again, he will be
redirected to the locked web page, and have to login.
There are four steps to do this:
1. Download this ZIP file to your local computer. Download.
2. Unzip it, and open the .htaccess file with Windows Notepad.
3. Edit the .htaccess file in this way:
The .htacess file is as follow:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite.com/locked.htm$
[NC]
RewriteRule .*\.(pdf|doc|xls|ppt)$ http://www.yoursite.com/locked.htm
[R,L,NC]
You should change the strings in second and third lines "yoursite.com/locked.htm"
to the URL web address or your locked page. For example, if
the web address of your locked page is http://www.mtopsoft.com/htmllock/pdflocked.htm
, that you should change the .htaccess file to:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mtopsoft.com/htmllock/pdflocked.htm$
[NC]
RewriteRule .*\.(pdf|doc|xls|ppt)$ http://www.mtopsoft.com/htmllock/pdflocked.htm
[R,L,NC]
4. Upload the modified .htaccess file to your web server, you
should place it to the same directory as the PDF files.
We have made an example of this. Please open the locked web
page (username: demo, password: demo) http://www.mtopsoft.com/htmllock/pdflocked.htm
, in which there is a link to a PDF file: http://www.mtopsoft.com/htmllock/myfiles/test.pdf
.
If you logs in the web page, then open or download the PDF
file, everything will be fine, but if you directly open the
link of the pdf file, you will be redirected to the login page.
If you had opened the PDF file online,
please clear the caches of your web browser before testing the
redirection.
|