0

I'm trying to convert requests like /download.php?name=one into /downloads/one.zip instead.

The following sends the correct file, but the client saves it as download.zip instead of one.zip

RewriteEngine On
RewriteCond %{REQUEST_URI} =/download.php
RewriteCond %{QUERY_STRING} ^name=(.+)$
RewriteRule ^/download.php$ /downloads/%1.zip

How do I get Apache v2.4.35 to send the client the new filename?

It looks like the old PHP would set an http header:

content-disposition: attachment; filename="one.zip"

Is there some way to tell Apache to always send the filename for files from /downloads or something?

Pascal
  • 493
  • 3
  • 11

1 Answers1

0

Probably not the only way, or the best way, but this is what I finally got to work:

<Location /download.php>
    RewriteEngine On
    RewriteCond %{QUERY_STRING} ^name=(.+)$
    RewriteRule /download.php$ /downloads/%1.zip [E=FILENAME:%1]
</Location>
<Location /downloads/>
    Header set Content-Disposition "attachment; filename=%{REDIRECT_FILENAME}e.zip" env=REDIRECT_FILENAME
    UnsetEnv REDIRECT_FILENAME
</Location>
Pascal
  • 493
  • 3
  • 11