1

I have the following mod_rewrite directive in my lighttpd config file:

url.rewrite-once = (
  "foo.*$" => "static/foo.pdf",
)

I'd like to hand out URLs like this: http://<server>/foo/r=ca2b912 (or similar), such that I can track the origin of the link in the http access log.

When I enter http://<server>/foo/r=131ab42, however, the "save-as" file dialog is shown and is proposing to name the file r=131ab42 (at least when using firefox). I'd like to have it propose foo.pdf as file name to save. This should work independent of the tool accessing the URL (ie. wget, IE, etc should all save the file as foo.pdf).

How can I achieve that? I've noticed that firefox corrects the file name when reloading the URL.

Please note: this is the first time I want to use a rewrite rule. I have tried to find the answer myself, but have not succeeded.

Sebastian
  • 189
  • 6

2 Answers2

2

rewrite is a server internal operation; the user doesn't see the result (unless you expose it manually in some way).

You could try the Content-Disposition header; but the best way is to fix your URLs (i.e. have .../foo.pdf from the beginning). You could use redirect rules for the migration.

Stefan
  • 859
  • 1
  • 7
  • 18
  • you are right: `http:///r=ca2b912/foo.pdf` works. Simple as that. This is an acceptable workaround for me. I also looked at your link, but that seems too complicated for my case. – Sebastian Aug 28 '14 at 20:48
  • I'll wait a couple of days with accepting in order to encourage other answers. Will accept if no other answers trickle in. Thanks. – Sebastian Aug 28 '14 at 20:50
2

You just need to prefix your r=ca92b32 string with a ? (ie: http://<server>/foo/?r=ca93b32)

The string will be considered as a parameter instead of a filename and won't be treated as a filename.