【发布时间】:2018-06-20 10:03:15
【问题描述】:
我想将Nginx 中的 url 'https://www.example.com/knowledges/qa/123456' 转换为 'https://www.example.com/knowledges/qa.html?id=123456'。
我是 Nginx 新手,请尝试以下方法:
root /opt/statics;
location / {
index index.html;
}
location /knowledges/qa/ {
rewrite ([^\/]+)\/?$ /knowledges/qa.html?questionId=$1 last;
}
正则表达式/([^\/]+)\/?$/g可以匹配url最后一个片段的组(即123456)。
== 编辑 ==
添加最后一个斜杠/knowledges/qa/ 有效。 (否则死循环)
然后,新的问题出现了。在qa.html 中检索文档位置:
document.location.href // https://www.example.com/knowledges/qa/123456
不是预期的https://www.example.com/knowledges/qa.html?id=123456?
【问题讨论】:
-
日志是怎么说的?
-
死循环。查看更新。
-
如果您有不同的问题,那么您应该提出一个新问题
标签: nginx nginx-location