I am trying to force PDFs to download and not open in user browser so I add this snippet to .htaccess but it causes internal server error.
<FilesMatch “.(pdf)$”> ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch>
I used this code before on shared hosting. Plus I tried other snippets but it seems like when ever I edit .htaccess from console or ftp it causes internal server error.
My default working .htacces with 664 permission
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(..php)$ $2 [L] RewriteRule . index.php [L] </IfModule>
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Click below to sign up and get $100 of credit to try our products over 60 days!
Please pastebin the .htaccess file using the following command: <br><pre>cat /path/to/.htaccess | curl -F ‘sprunge=<-’ http://sprunge.us</pre>
Sorry, I am new to digital ocean here is the snippet again : <br><code> <br>FilesMatch “.(pdf)$” <br> ForceType application/octet-stream <br> Header set Content-Disposition attachment <br>/FilesMatch <br></code> <br>