I have many PDFs in a \drawings
folder on my server. The filename structure is: 8 digits, underscore, Rev level letter -- i.e. \d{8}_[A-Za-z]\.pdf
. These files are organized in subfolders that match the first 4 digits of the filename -- \drawings\1500\
, \drawings\1600\
etc.
I want users to be able to call up a drawing in the browser, not knowing the REV level, by using just the first 8 digits. e.g.
intranet.com/drawings/15003915 -> Z:\drawings\1500\15003915_D.pdf
intranet.com/drawings/16000423 -> Z:\drawings\1600\16000423_B.pdf
in nginx.conf
, I have the following
location ^~ /drawings/ {
try_files $uri @redirect;
}
location @redirect {
if ($uri ~* "^/(\d{8})$") {
set $filename $1;
rewrite ^/(.*)$ Z:/Drawings/${$uri:1:4}/$filename_[A-Z].pdf last;
}
return 404;
}
NGINX regex has always thrown me. I keep getting errors on the rewrite
line.
Ideas on how to fix?