we have a large php application running on apache now which I would like to migrate to nginx. I’ve got everything to work correctly except for a RewriteRule in a .htaccess file.
The web app allows the user to store files which can be publicly downloaded. The files on the server can be found in the web root under their account folder, which is their domain name without subdomain and domain extension. So for the domain subdomain1.domain2.com the accountname = domain2
/files/{account}
Some examples:
/files/domain1/
/files/domain2/
/files/domain3/
However we want to have urls like https://subdomain1.domain1.com/files/file.pdf instead of https://subdomain1.domain1.com/files/account/file.pdf
This is the RewriteRule which works on apache.
RewriteCond %{HTTP_HOST} [www\.|subdomain1\.|subdomain2\.]?
(domain1|domain2|domain3).(com|nl|org)+
RewriteCond %{REQUEST_URI} !files/(domain1|domain2|domain3)+\/
RewriteRule files/(.*) files/%1/$1 [L]
However trying to port this to nginx gives me headaches. I’ve tried the available options here (https://www.nginx.com/blog/creating-nginx-rewrite-rules/) but nothing seems to work as I want it.
Anyone has an idea on how to do this?