SetEnvIf regex for setting Content-Disposition HTTP header

apache-2.2regex

I am attempting to use the IHS 7.0/apache 2.2 SetEnvIf directive to set the filename of a downloaded file based on a url parameter. I think I am pretty close, however if there is a space (encoded or otherwise) in the filename – it fails.

example url:

http://site.com/path/to/filename.ext/file-title=Nice File Name.ext?file-type=foo

apache config:

SetEnvIf Request_URI "^.*file-title\=(.*)\??.*$" FILENAME=$1
Header unset "Content-Disposition"
Header add "Content-Disposition" "attachment; filename=%{FILENAME}e"
UnsetEnv FILENAME

An application will specify what is now showing up as "Nice File Title.ext" in the example. This all works great if there are no spaces, however – if there is a space the filename to download will just show up as "Nice". There may or may not be a second set of parameters in the query string (?file-type, etc)

Best Answer

ok - so leaving the regex alone and changing the Header add did the trick.

filename=\"%{FILENAME}e\""

to enclose it in quotes. sigh.