How to prevent your PDF files from opening in a web browser...

5 replies
Normally, when clicking on a link to a pdf file, the file opens within
the web browser window.

To prevent this, your host must support URL rewriting via htaccess.
Download the .htaccess file in the root directory of your website.
Download it in two copies in two different folders on your computer.
You will not modify one of these copies to undo your changes if
something goes wrong.

If you have no .htaccess file in that directory, simply create one.
Create a htaccess.txt file with a text editor like Notepad++. You
will only have to upload it to the root directory of your website
and rename it .htaccess.

In your .htaccess file (or htaccess.txt, depending on your situation),
add the following code:

<IfModule mod_headers.c>
<FilesMatch ".(pdf|zip)$">
ForceType application/octet-stream
Header set Content-disposition attachment
You can add other file extensions between the two parentheses.

Then upload your file to the root directory of your website, and
rename it .htaccess when necessary. Display your website with
your browser to make sure everything works well. In case of
problems, delete your .htaccess file or replace it with the original
version to undo your changes.
#browser #files #opening #pdf #prevent #web

Trending Topics