1

I have the following configuration file in my sites-available

<VirtualHost *:80>
    ServerName my.domain
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>
<VirtualHost *:443>
    ServerName my.domain
    DocumentRoot /var/www/html
    ErrorLog /var/www/logs/error.log
    CustomLog /var/www/logs/access.log combined
    SSLEngine on
    SSLCertificateFile /var/www/certs/certificate.pem
    SSLCertificateKeyFile /var/www/certs/private.key
    SSLCertificateChainFile /var/www/certs/ca_bundle.pem
    <Directory /var/www/html>
            Options -Indexes
            AllowOverride All
            Require all granted
    </Directory>
    <Directory /var/www/html/nav>
            DirectoryIndex nav.exe
            AllowOverride All
            Require all granted
    </Directory>
</VirtualHost>

And when I go to https://my.domain/nav, I expect it to download the file as nav.exe. But instead, it downloads it as 'download`.

How can I set a custom name for this download?

Mz.
  • 17
  • 1
  • 7
  • 1
    From memory the filename gets set in an http header. Part of content-disposition I think. – hookenz Jun 12 '17 at 23:06
  • Related. https://serverfault.com/questions/101948/how-to-send-content-disposition-headers-in-apache-for-files – hookenz Jun 12 '17 at 23:13
  • @Matt ok, im unsure how to set content dispositions even after googling and looking at the related question. Think you can still help me? – Mz. Jun 13 '17 at 03:40
  • I'm not really that familiar with Apache. It's been a while. I'll attempt an answer below. It make not work. – hookenz Jun 13 '17 at 20:28

1 Answers1

0

Not really sure if this will work as I'm not familiar with Apache. But a quick google and perhaps something like the following will work:

First enable the apache module mod_headers See here on how to do that.

Then set your Directory block in sites-enabled to:

<Directory /var/www/html/nav>
    DirectoryIndex nav.exe
    AllowOverride All
    Require all granted
    SetEnvIf Request_URI "^.*/([^/]*)$" FILENAME=$1
    Header set "Content-disposition" "attachment; filename=%{FILENAME}e"
    UnsetEnv FILENAME
</Directory>

The e at the end of {FILENAME} apparently means contents of FILENAME environment. So don't leave that off. If this works, I'm not sure if that will result in a file that want's to be called nav.exe or nav.

This is an adapted sample of the link I sent you. Try it and see.

hookenz
  • 14,472
  • 23
  • 88
  • 143
  • unfortunately, it doesnt work – Mz. Jun 14 '17 at 17:14
  • Are you able to use wireshark and examine the headers to see if it even came through? Turn on debug logs in the server. It seems header set can be used anywhere. – hookenz Jun 14 '17 at 19:14
  • Sorry for the half-a-year gap. In the end, I couldn't get it to work and resorted to PHP header setting. I managed to achieve it by setting the `Content-Type` header. I tried doing it in the configuration itself, but it still wouldn't work. Thanks anyway! – Mz. Oct 15 '17 at 02:39