Nginx重定向到带有/#/url的url

Nginx重定向到带有/#/url的url,nginx,Nginx,我不熟悉使用nginx,我正在尝试将一个url重定向到另一个 https://server.com/#/page.html -> https://server.com/page.html /#/来自使用Angular2的路由器功能。我决定将页面更改为静态html,因为Angular2在启动时加载整个应用程序,因此没有必要以这样的方式显示这一页信息 我试图解决这个问题的方法如下。我可以从/anotherpage->/page.html重定向,但是/#/anotherpage->/page.html

我不熟悉使用nginx,我正在尝试将一个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;
    }
}

欢迎对最佳实践提出任何建议。

遇到
#
错误后,浏览器不会发送任何信息

因此,当发送
https://server.com/#/page.html
仅限
https://server.com/
由nginx查看


因此,重定向是不可能的,更改客户端应用程序是唯一的选择。

遇到
后,浏览器不会发送任何信息

因此,当发送
https://server.com/#/page.html
仅限
https://server.com/
由nginx查看


因此,重定向是不可能的,更改客户端应用程序是唯一的选择。

对此有很多答案。您不能,因为浏览器从不向服务器发送散列部分,所以您的nginx将始终看到对
/
的请求。谢谢,我不知道这一点。要详细说明我是否有
/folder/#/loremipsum
只是
/folder/
然后发送到服务器?很抱歉,我把编辑搞错了。我没有看到任何与
/
匹配的位置。您的位置
location=/#/anotherpage
实际上匹配
example.com/%23/anotherpage
Yes
example.com/%23/anotherpage
确实匹配。Angular2应用程序提前加载所有内容,然后根据未发送到服务器的数据更改视图,因此我的链接应该在客户端更改。对此有很多答案。您不能,因为浏览器从不向服务器发送散列部分,所以您的nginx将始终看到对
/
的请求。谢谢,我不知道这一点。要详细说明我是否有
/folder/#/loremipsum
只是
/folder/
然后发送到服务器?很抱歉,我把编辑搞错了。我没有看到任何与
/
匹配的位置。您的位置
location=/#/anotherpage
实际上匹配
example.com/%23/anotherpage
Yes
example.com/%23/anotherpage
确实匹配。Angular2应用程序提前加载所有内容,然后根据未发送到服务器的数据更改视图,因此我的链接应该在客户端更改。