想把 /s123 rewrite 到 /survey/shortid/survey_id/123
rewrite "^/s(\d+)(.*)$ /survey/shortid/survey_id/$1$2 permanent;
但是死活不工作,查来查去有人说他加上host就好了,于是改为
rewrite "^/s(\d+)(.*)$ http://$host/survey/shortid/survey_id/$1$2 permanent;
最后进一步改进为
rewrite "^/s(\d+)(.*)$ $scheme://$host/survey/shortid/survey_id/$1$2 permanent;
对于非要加$host不可感到有些多余,但是又没有更好的解决办法,先这样用着吧
rewrite "^/s(\d+)(.*)$ /survey/shortid/survey_id/$1$2 permanent;
但是死活不工作,查来查去有人说他加上host就好了,于是改为
rewrite "^/s(\d+)(.*)$ http://$host/survey/shortid/survey_id/$1$2 permanent;
最后进一步改进为
rewrite "^/s(\d+)(.*)$ $scheme://$host/survey/shortid/survey_id/$1$2 permanent;
对于非要加$host不可感到有些多余,但是又没有更好的解决办法,先这样用着吧
本文介绍了一种特定的Nginx rewrite规则的调试过程。作者尝试将URL路径从/s123重写为/survey/shortid/survey_id/123的形式,并分享了遇到的问题及解决方案。最终通过添加$host变量实现了预期的功能。
820

被折叠的 条评论
为什么被折叠?



