How To Fix Mp3, Mp4, Pdf, and different recordsdata opening in browser as a substitute of downloading right away.
Lately many WordPress customers have been dealing with the problem of wanting folks to obtain your recordsdata straight away, as a substitute they hold opening in browsers.
Don’t fear I simply obtained slightly repair however notice; it would not work on each host server.
According to my analysis, I learnt that this technique I’m about to share works on 80% of shared host servers whereas the remaining 20%, could also be by likelihood the trick/repair ain’t gonna work.
If you are internet hosting your web site on servers like namecheap, siteground, whogohost, abollyhost, and lots of extra, that is going to be just right for you.
I don’t need to hold this secret to myself which is why I’m going to share with you proper now.
How To Force A File To Download
Zip The File
- On your computer or smartphone, you may get an archive viewer like zip, which I assume ought to have the ability to zip a file other than viewing.
- Select the file you need to add in your web site, zip it, then add. The file ought to have the ability to obtain robotically. Note: It’s actually not a good suggestion generally… Unlike your audio recordsdata, it is not everyone that is aware of what it is prefer to zip and unzip a file, so when folks discover it tough to get your recordsdata downloaded within the right format, they are going to give up coming to your web site.
Through Your .Htaccess
If you’re actually into web site designing and improvement, it’s best to know what htaccess means.
Htaccess is a file in your web site’s file supervisor and I can say it’s what make your web site to have the ability to execute sure instructions.
Making adjustments to htaccess is at all times not advisable in case you have no idea what you’re doing.
Htaccess in different phrases, whether it is absent you web site will not present up, in case you enter the fallacious code, you would possibly get sure errors just like the “503 error” and so forth.
So at all times watch out everytime you’re coping with htaccess file.
I will not deal with you as in case you’re an professional, an novice would possibly as nicely be studying this, sorry for that phrase, so I’ve to interrupt it down.
Where can we discover the .htaccess?
- Login to your host server’s management panel (Cpanel)
- Go to file supervisor, click on on the public_html, you will note some recordsdata within the root. In some server it’s at all times hidden, so if doable attackers obtained their means into your server they will not have the ability to discover it speak much less of making adjustments to it. So if you wish to make it present, click on on the settings button that’s about the fitting prime nook, there you will see “show hidden files”.
- Tick, then save.
- Your htaccess ought to seem now.
- Click on it and edit it.
Now Applying the Code in Your Htaccess
I advised you earlier that it’s dangerous. But don’t panic. Before making adjustments to your htaccess, be sure to obtain it (have a backup of the htaccess file) in case something goes fallacious. How to obtain, long-press on the htaccess file, it’s best to see obtain among the many choices that come out.
Now forcing download audio|mp3|pdf|mp4 file(s) to download immediately, you must apply this code:
<FilesMatch ".(?i:pdf)$"> ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch>
The code above works solely in order for you just one file sort to force-download. As you possibly can see, this solely works for pdf files. If you need it to work just for audio files, like Mp3, you simply should delete the pdf there and put Mp3.
On the opposite hand if you wish to include multiple files, use the code below:
<FilesMatch ".(mov|mp3|jpg|pdf)$"> ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch>
You can see it combines, mov, Mp3, jpg and pdf collectively, without delay. If you continue to need to add extra file sort, all you must do is to incorporate |file sort throughout the bracket.
Note: The code must be utilized simply earlier than the #End WordPress Tag within the htaccess.