0

Is the following behaviour possible only with nginx directives?

I want to visit the page: https://example.com/xyz When hitting enter in the adressbar I want an immediate download of the file abc.tst to be presented to the user but the adressbar should not change, it should "stay" on https://example.com/xyz and not go to https://example.com/abc.tst and the name of the downloaded file should not change to xyz.

I have experimented with various rewrite rules, or locations but can't seem to figure it out...

1 Answer 1

0

You need to use the Content-Disposition HTTP header to speficy filename different from xyz:

location = /xyz {
    alias /path/abc.tst;
    add_header Content-Disposition 'attachment; filename="abc.tst"';
}

You may also need to specify MIME type for this file, use default_type directive, for generic binary data try

default_type application/octet-stream;
3
  • Thank you, this sounds and looks right an makes sense, but unfortunately it gives me 404, I'll keep trying to correct the mistake which I suspect on my end... Commented May 20, 2021 at 22:09
  • You need to specify full path to abc.tst including the filename itself. And I changed location /xyz to location = /xyz, it is more correct. Commented May 20, 2021 at 22:13
  • The full (absolute) path did the trick, since I specified a root directory in the server directive I specified a relative path in the alias. Thank you very much, this does exactly what I asked for and helped me a lot. Commented May 20, 2021 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.