如何携带参数访问 nginx 下的静态资源?

2019-07-12 17:50:50 +08:00
 ming7435
server {
        listen       80;
        server_name  xxxx.com;

        access_log  /tmp/access.log  main;
        error_log   /tmp/logs/error.log;


         location / {
            root /var/www/test/;
        }
    }    

上面是 nginx 的配置,现在访问 http://xxxx.com/aaa.html?id=123,在页面加载完之后取不到 id 字段。请教各位大神有办法解决吗?

1327 次点击
所在节点    问与答
5 条回复
ysc3839
2019-07-12 18:00:02 +08:00
你是怎么取的 id ?
ming7435
2019-07-12 18:08:35 +08:00
@ysc3839

function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return unescape(r[2]);
return null; //返回参数值
}
whwlsfb
2019-07-12 18:11:16 +08:00
这明显不是 nginx 的锅
ming7435
2019-07-12 18:15:53 +08:00
@whwlsfb 我也知道这不是 nginx 的锅,应该是我使用姿势不对,但是不知道咋写才能正确获取到
ysc3839
2019-07-12 18:35:53 +08:00
@ming7435 没记错的话有直接获取 url args 的接口吧?不需要正则表达式。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/582463

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX