we have an application which downloads the files from the server. After the download them it needs to save it, for that it uses the filename paramter which is comming from t
I have no idea if it works, but this would be my first attempt.
RewriteRule [^/]+\.pdf$ - [E=FILENAME:$0]
<FilesMatch "\.(?i:pdf)$">
Header set Content-Type application/octet-stream
Header set Content-Disposition "attachment; filename=%{FILENAME}e"
</FilesMatch>
EDIT Seems some apache installs prefix the env variable with REDIRECT_
RewriteRule [^/]+\.pdf$ - [E=FILENAME:$0]
Header set Content-Type application/octet-stream env=REDIRECT_FILENAME
Header set Content-Disposition "attachment; filename=%{REDIRECT_FILENAME}e" env=REDIRECT_FILENAME
Above code doesn't work out of the box. In my case, I needed another internal redirect.
But why would you need to set the filename in the header if the request URL contains the filename too? All browsers will save the file with under the name in the URL. So going to /path/test.pdf
will result in browsers suggesting the filename test.pdf
.