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'匹配 –