Force download of files


I am trying to force the download of pdf files from my server, rather than open them in the browser.

I have unsuccessfully tried

location ~* /wp-content/(.+.pdf)$ { internal; add_header Content-disposition “attachment; filename=$1”; }

Any suggestions?


try something like this

server { listen 80; server_name; location ~ ^.*/(?P<request_basename>[^/]+\.(pdf))$ { root /path/to/pdf/folder/ add_header Content-Disposition 'attachment; filename="$request_basename"'; } } let me know if that works for you.