Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

.htaccess file not working

Featured Replies

I was hoping someone could help me out here. I just created a new webpage with hostgator and I placed a .htaccess file in the public_html folder to force download of a pdf. For some reason it's not working. I've used the exact same .htaccess file on a webpage through hostgator a couple of years ago and it worked perfectly back then. Here is the script in the file:


<Files *.PDF>

ForceType application/pdf

Header set Content-Disposition attachment

</Files>


I've also tried:


AddType application/octet-stream .pdf



What could be wrong? The directory setup of my webpage files? Some sort of conflict between the webpage html and this .htaccess file?


Any help on this would be much appreciated. I just spent half a day yesterday looking for answers to this with no luck.

As opposed to making it viewable in the browser, so the only way the user can view it is by downloading it I'd guess? It sounds a bit dodgy at first but if a large pdf tried automatically opening on a slow connection it could be pointed out as a usability issue and I believe the user would still have to click a link pointing to the file before anything happened.

 

I don't know much about htaccess at all, I didn't even know this was possible until I read this but I've just tried a quick test now and this works for mp3s:

<FilesMatch "\.(?i:mp3)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
 

So is this any better for your pdf?

<FilesMatch "\.(?i:pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
 

The user would still have to click a link but once they did the file would just download rather than opening in their browser. I think...

 

From here: http://www.thingy-ma-jig.co.uk/blog/06-08-2007/force-a-pdf-to-download

 

and here: http://www.saelboat.com/blog/2012/12/htaccess-guide-force-downloads-of-mp3s-pdfs-and-other-media-files-299

Edited by JustOliver

 

I was hoping someone could help me out here. I just created a new webpage with hostgator and I placed a .htaccess file in the public_html folder to force download of a pdf. For some reason it's not working. I've used the exact same .htaccess file on a webpage through hostgator a couple of years ago and it worked perfectly back then. Here is the script in the file:
<Files *.PDF>
ForceType application/pdf
Header set Content-Disposition attachment
</Files>
I've also tried:
AddType application/octet-stream .pdf
What could be wrong? The directory setup of my webpage files? Some sort of conflict between the webpage html and this .htaccess file?
Any help on this would be much appreciated. I just spent half a day yesterday looking for answers to this with no luck.

 

To force file downloads via .htaccess you must be running on apache.

  • 2 years later...

Hi FLman, sorry ahead to bump this up but may you please share the steps on how you were able to get this to work? I mean htaccess. 1.gif

  • 4 weeks later...
//original code

header ("Content-disposition: attachment; filename=" . str_replace(" ", "_", basename($file)) . ";");


//remove semi-colon from end of contructed file name

header ("Content-disposition: attachment; filename=" . str_replace(" ", "_", basename($file)));

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.