0
我是新使用nginx,我試圖重定向一個網址到另一個。Nginx重定向到URL與/#/ url
https://server.com/#/page.html -> https://server.com/page.html
的/#/
來自使用Angular2的路由器功能。我決定將頁面更改爲靜態HTML,因爲Angular2在啓動時加載了整個應用程序,而沒有必要將這一頁信息呈現給用戶。
我試圖解決這個問題如下。我可以從/anotherpage -> /page.html
重定向,但/#/anotherpage -> /page.html
加載Angular2應用程序並嘗試路由到不存在的路線。
使用這個配置和位置指令:
server {
listen 8001;
server_name server.com;
...
#SSL Things
...
root /to/root/folder/public;
#Redirects:
location = /anotherpage {
rewrite ^/.* https://$server_name/page.html;
}
#Does not redirect:
location = /#/anotherpage {
rewrite ^/.* https://$server_name/page.html;
}
}
的最佳做法的任何建議,歡迎爲好。
有很多答案。你不能因爲瀏覽器永遠不會發送哈希部分到服務器,所以你的nginx將總是看到請求'/' –
謝謝我不知道這一點。詳細說明,如果我有'/文件夾/#/ loremipsum'只是'/文件夾/'然後發送到服務器?對不起,我搞砸了編輯。 –
我沒有看到任何匹配'/'的位置。你的位置'location = /#/ anotherpage'實際上與'example.com /%23/anotherpage'匹配 –