Nginx 使用/#/url 重定向到 url [英] Nginx redirect to url with /#/url

查看:99
本文介绍了Nginx 使用/#/url 重定向到 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用 nginx,我正在尝试将一个 url 重定向到另一个.

I'm new to using nginx and I'm trying to redirect one url to another.

https://server.com/#/page.html ->https://server.com/page.html

/#/ 来自使用 Angular2 的路由器功能.我决定将页面更改为静态 html,因为 Angular2 在启动时加载了整个应用程序,并且没有必要将这一单页信息显示为这样.

The /#/ comes from using Angular2's router functionality. I decided to change the page to static html because Angular2 loads the entire app at start up and it's unnecessary for this single page of information to be presented as such.

我解决问题的尝试如下.我可以从 /anotherpage -> 重定向/page.html/#/anotherpage ->/page.html 加载 Angular2 应用程序并尝试路由到不存在的路由.

My attempts at solving the problem is as follows. I can redirect from /anotherpage -> /page.html but /#/anotherpage -> /page.html loads the Angular2 app and tries to route to the non existent route.

使用这个配置和位置指令:

Using this config and location directives:

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;
    }
}

也欢迎对最佳做法提出任何建议.

Any suggestions on best practices are welcome as well.

推荐答案

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

The browser does not send any information after a # is encountered.

因此在发送 https://server.com/#/page.html 时,nginx 只能看到 https://server.com/.

Thus when sending https://server.com/#/page.html only https://server.com/ is seen by nginx.

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

Thus redirecting is not possible and changing the client side application is the only option.

这篇关于Nginx 使用/#/url 重定向到 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆