L
L
Leonid2018-11-06 12:25:02
Apache HTTP Server
Leonid, 2018-11-06 12:25:02

Downloading an image file from a link using .htaccess - how?

How to make it through .htaccess so that if we set some GET download variable equal to 1 when accessing a file, then the file does not open in the browser but starts downloading?
For example, to make the following download link possible:

mysite.ru/1.jpg?download=1

I try
<FilesMatch "\?download=1$">
  Header set Content-Disposition attachment
</FilesMatch>

something does not help - probably something is not right ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2018-11-12
@easycode

For Apache 2.4
If Apache version is below 2.4

Header set Content-Disposition attachment env=attach

RewriteCond %{QUERY_STRING} =download=1
RewriteRule ^ - [E=attach:1]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question