I have a site configuration pointing to /var/www for a domain (https://somedomain.com/) but I want a location /clientfolder to be redirected to /home/clientfolder/website/
My issue is whenever a request comes in, such as https://somedomain.com/clientfolder/index.html the daemon is looking for a file at /home/clientfolder/website/clientfolder/index.html
So I tried to use the rewrite directive:
location /clientfolder {
rewrite ^/clientfolder/(.*)$ /$1 last;
root /home/clientfolder/website
}
But now https://somedomain.com/clientfolder/index.html loads the file at /var/www/index.html
Is there another directive than rewrite that would allow me to strip the "clientfolder" from the file path if the /clientfolder location was matched?
Update: I managed to get this to work, but it feels totally wrong:
location /clientfolder/website {
root /home;
}
location /clientfolder {
rewrite ^/clientfolder/(.*)$ /clientfolder/website/$1;
}
答案 0 :(得分:1)
如果以/clientfolder
开头的URI位于/home/clientfolder/website
中,则应使用alias
指令。
例如:
location /clientfolder {
alias /home/clientfolder/website;
}
有关详细信息,请参见this document。