This question follows on in many ways from a previous one I had asked - and ended up answering myself. A brief summary of the problem I describe there and my solution to it
- I need to perform different default actions when there is an attempt to access files in a subfolder depending on who is attempting the access
aa
- A "back-office" web app in which case the file is delivered if it exists or a "stub" is generated and echoed back if it does not
- In response to requests from a phone app, OTH, I want to deliver the file, if it exists, or a HTTP 404 if it does not
The solution I worked out is as follows
- Create a symlink to the folder in question
ln -s /path/to/folder /path/to/bo_folder
where the prefix bo_
on the symlink stands for back-office
- When fetching files from the app just try to reach them directly as
/path/to/folder/file.name.extn
in which case Nginx will deal with sending back a 404 or the file, as it deems right
- When fetching files for editing in the backoffice suite access them as
/path/to/bo_folder/file.name.extn
The following Nginx configuration block
location /path/to/bo_folder
{
add_header Access-Control-Allow-Origin *;
rewrite ^(.*)$ /path/to/folder/index.php?$1 last;
}
The issue to which I am now trying to find a more graceful solution is this one - I don't just have one such folder but rather a whole sequence of them /path/to/folder_1, /path/to/folder_2... /path/to/folder_n
While I can put in location
blocks for each such folder is possible it is tedious and error prone. There is almost certainly a way to write the rewrite more generically one folder level up, i.e. in /path/to
rather than for each individual sub folder.
There is a minor complication here - I cannot handle this by having a rewrite to a /path/to/index.php
folder since the stub content I need to send back is quite different depending on the subfolder in which that content is supposed to be.
My rather sketchy knowledge of Nginx configuration lets me down here. How can this be done?