Add header in apache

I have apache and many images on this server. E. g.: I want to have possibility do this: if user go to url like this must add header Content-Disposition: attachment; filename="abc.jpg". How I can do it?

You want to use a combination of mod_rewrite (to fake the “download” directory) and mod_headers (to add the Content-Disposition header).

Create a .htaccess file in the images directory:

<filesmatch ".*">
Header set Content-Disposition attachment env=REDIRECT_force_download

This will set the appropriate header whenever the “REDIRECT_force_download” environment variable is set.

Create a download directory and add this .htaccess file:

RewriteEngine On
RewriteRule (.*) ../$1 [L,NC,QSA,E=force_download:1]

This will redirect any image requests to the parent (images) directory while adding the “REDIRECT_force_download” environment variable that will trigger the Header command from above.



Add header in apache》有2个想法


电子邮件地址不会被公开。 必填项已用*标注