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
http://test.com/images/download/abc.jpg apache 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 </filesmatch>
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.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki