Forcing a File to Download in a Browser Via .htaccess

Forcing A File To Download in A Browser Via .htaccess

.htaccess is a powerful hidden text file that offers a link between the server and clients domain. Its designed to allow a higher access of files by the website visitors as configured. The website owner may set a default MIME Apache that makes your files to be displayed on the browser and not be downloaded in your machine. This may not be what your website visitors prefer because perhaps with them having a link of where they can download the files, and keep them is at times pleasing. On the other hand there maybe visitors who dont focus on downloading your files. Regardless of the case, a file can be forced to download through .htaccess to avoid displays only. This is by editing some codes in files through htaccess changing the last bit to pdf,doc,txt,movie or anything you want it to be.

Procedures

  • Login to cpanel
  • Click of file- filemanager
  • Locate public-html- then .htaccess and right click on it to edit
  • Add a code on every file at the top and the file extension should differ. The file extension will define where the download of the set particular file will be downloaded. Files can be images, texts ,audios etc

For example – (AddType
application/octet-stream pdf
) or (AddType application/octet-stream .mov) here files will be downloaded through pdf extension and videos by mov extension.

  • Finally click save changes at the far right corner.

Was this article helpful?

Related Articles

Leave A Comment?