Rewrite rule fir NGINX

老子叫甜甜 提交于 2019-12-13 06:13:09

问题


I'm pretty bad in reg expression and nginx rewrite rules. I need help to figure rewrite rules for the following situation for NGINX.

http://example.com/blog/category1/postname => http://example.com/category1/postname
http://example.com/blog/category1/helloworld => http://example.com/category1/helloworld

Thank you in advance!


回答1:


this one is pretty simple, you just want to tell nginx to ignore the word blog ( and I'll assume it has to be followed with the word category1 )

rewrite ^/category1/(.*) /blog/category1/$1 last;
#       |      |      |     |            |    |
#      [1]    [2]    [3]   [4]          [5]  [6]

[1]: URL begins with
[2]: category1
[3]: capture all that follows
[4]: add blog
[5]: add the rest of the URL ( that we captured in [3] )
[6]: stop the rewrite and process the new URL and any other matching rewrites.



来源:https://stackoverflow.com/questions/18045699/rewrite-rule-fir-nginx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!