Categories: Tips & Tricks

Force Download Specific Files with Apache & Htaccess

At time we want visitors to download instead of viewing the file instead of viewing inside their browser. As a visitor I have faced problems with PDF files at many sites where I wanted to download the PDF file and view it separately because viewing the PDF inside the browser slows down the browser and sometimes causes the browser to crash.

So, If you want to force people to download a file or all files in a specific directory and so on, if is very easy to do so with the help an Apache directive which sets the response header ‘Content-Disposition’ to ‘attachment’, see the examples below:

[code]
<Files *.pdf>
Header set Content-Disposition attachment
</Files>

<Directory /var/www/html/images>
Header set Content-Disposition attachment
</Directory>
[/code]

Do not forget to share if you like:
Pradeep

Recent Posts

Self-hosting free password manager : Vaultwarden

Bitwarden is an open-source password manager that helps individuals and organizations securely store, manage, and…

9 months ago

Get Started with IPTV: Free and Paid Options for All Devices

In today's digital age, traditional cable TV is steadily being replaced by more flexible and…

11 months ago

Installing Log2RAM utility on your Raspberry Pi

log2ram is a utility specifically designed for Linux-based systems, particularly single-board computers like the Raspberry…

11 months ago

ChatGPT Voice Shortcut on iOS, Android

How to Add a ChatGPT Voice Shortcut on iOS and Android With voice commands and…

11 months ago

Proxy Through SSH Tunnel

For occasional VPN or proxy, you do not always need to pay for a reliable…

1 year ago

Unlocking the Power of Time Machine: The Easiest Way to Back Up Your Mac

When it comes to protecting your Mac, Time Machine offers an effortless and powerful way to keep…

1 year ago