SetEnvIf regex for setting Content-Disposition HTTP header

Posted by Erik Sorensen on Server Fault See other posts from Server Fault or by Erik Sorensen
Published on 2010-05-24T21:51:46Z Indexed on 2010/05/24 22:02 UTC
Read the original article Hit count: 416

Filed under:
|
|

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)

© Server Fault or respective owner

Related posts about apache

Related posts about regex