angular - 使用 nginx 将遗留 URL 重定向/重写到需要哈希的 Angular 应用程序
问题描述
我有一系列指向遗留应用程序的现有链接,这些链接需要由使用哈希 URL 格式的 Angular 应用程序处理。
例如,像这样的旧 URL:
example.com/downloads/anexistinguuid
需要在 nginx 中重定向到这个:
example.com/#/downloads/anexistinguuid
我尝试了以下方法:
location /downloads {
proxy_pass example.com/#/downloads/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
但这似乎不是正确的方法。
有很多关于如何从 URL 中删除散列的示例,但此时我无法更改 Angular 应用程序的 URL 策略,并且必须保持与已经存在的大量链接的兼容性,而我也可以t 改变。
解决方案
您可能需要重定向而不是反向代理。
尝试:
location /downloads {
return 301 /#$request_uri;
}
推荐阅读
- python - 如何将文本放在图像下方的中心?
- c# - 我想在 discord.NET 中执行 unban 命令,我这样做了,但它不起作用。你能帮助我吗?
- python - 正则表达式匹配类方法的动态装饰器
- typescript - 如何指定一个属性类型必须扩展另一个类型?
- asp.net - 如何从asp net中的用户角色表中获取角色ID
- javascript - 在for循环中将文件异步写入服务器
- c++ - 如何从向量中删除对象
? - r - 如何根据选择的事件在 ggplot 中更改我的字幕
- python - 使用正则表达式从 word 文件中收集数据
- amazon-web-services - 通过 Yum 在 Amazon AWS EC2 上安装 Couchdb 失败