apache - 在不更改前端代码的情况下禁用哈希 URL(如 http://localhost/#/login)
问题描述
我想禁用哈希 URL(如http://localhost/#/login)但我无法更改前端代码。我可以通过其他方式(如 Nginx 或 Apache Config)解决它吗?
解决方案
它可以重定向
#/foo
本演示中的哈希 URL https://jsfiddle.net/yaoyuan/exLwhy57/1/安装 Nginx。在 Mac 上使用https://github.com/denji/homebrew-nginx
为 Mac 安装 Nginx 模块 https://denji.github.io/homebrew-nginx/#modules brew reinstall nginx-full --with-sub-module; 然后我们可以使用 sub_filter 表达式 https://nginx.org/en/docs/http/ngx_http_sub_module.html
删除demo1中的js代码,得到demo2 https://jsfiddle.net/yaoyuan/exLwhy57/2/;
- 使用这个 nginx 配置
location / {
root html; (use your folder)
index index.html index.htm;
sub_filter </head>
'</head><script>
function redirect() {
if (location.hash === "#/foo") {
window.location.replace("https://example.com");
}
}
window.onhashchange = function() {
if (location.hash === "#/foo") {
window.location.replace("https://example.com");
}
}
redirect();
</script>';
sub_filter_once on;
}
- 运行
nginx -c nginx.config
以使用此配置
我们可以在 HTML 中找到一个新的片段,然后我们解决这个问题。
推荐阅读
- c# - 如何通过 Impala ODBC 批量插入?
- c# - 如何在 ReSharper 的 for/foreach/while/... 标头中缩进附加行?
- typescript - 将泛型变量传递给嵌套函数
- r - 如何计算 R 中具有可变消耗水平的滚动总和?
- java - 即使启用了版本控制,Google 云存储 Blob.delete() 也不会创建存档
- macos - launchctl load -w 没有那个文件或目录
- assembly - 如何在汇编代码中调用 fprintf() 函数?
- python-3.x - 为什么boto3的connect方法中的主机名不接受变量值
- php - 如何将 curl 设置为模块控制器
- batch-file - 制作批处理文件以传输文件名包含特定数字的文件