i am serving .pdf
files using nginx web server. and setting filename of .pdf
file using rewrite rule , depending on the title args
.
what i am trying to do is, add my domain name example.com
in the filename
1. if title
var contains example.com
in it then use title
var data for filename.
e.g.
URL : http://example.com/pdf/0D2E8C9DC2F732A6ACC6150811515F697E3C376C.pdf?title=[example.com]ebook
Filename : [example.com]ebook.pdf
2. if title
var does not contains example.com
in it then make filename as [example.com]title var.pdf
e.g.
URL : http://example.com/pdf/0D2E8C9DC2F732A6ACC6150811515F697E3C376C.pdf?title=ebook
Filename : [example.com]ebook.pdf
3. if title is not set then use filename as [example.com]hash.pdf
filename.
e.g.
URL : http://example.com/pdf/0D2E8C9DC2F732A6ACC6150811515F697E3C376C.pdf
Filename : [example.com]0D2E8C9DC2F732A6ACC6150811515F697E3C376C.pdf
How can i achieve something like this. ?
my current config looks like this
#pdf download block
location ~* /pdf/([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F]+)\.pdf$ {
#if title is not set then use hash.pdf as filename
if ( $arg_title = '' ) {
add_header Content-Disposition 'attachment; filename="[example.com]$1$2$3$4$5$6.pdf"';
}
add_header Content-Disposition 'attachment; filename="[example.com]$arg_title.pdf"';
alias /var/www/example.com/pdf/$1/$2/$3/$4/$5/$1$2$3$4$5$6.pdf;
expires 1y;
}
above code works fine only if title var is not set at all, but if i set title var as [example.com]ebook.pdf
it adds domain name one more time and the final filename becomes
[example.com][example.com]ebook.pdf