Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 reg 表达式和 nginx 重写规则方面很糟糕。我需要帮助来为 NGINX 的以下情况制定重写规则。
http://example.com/blog/category1/postname => http://example.com/category1/postname http://example.com/blog/category1/helloworld => http://example.com/category1/helloworld
先感谢您!
这个很简单,你只是想告诉 nginx 忽略这个词 blog (我假设它必须跟着这个词category1)
category1
rewrite ^/category1/(.*) /blog/category1/$1 last; # | | | | | | # [1] [2] [3] [4] [5] [6]
[1]:URL 以 [2] 开头:category1 [3]:捕获后面的所有内容 [4]:添加blog [5]:添加 URL 的其余部分(我们在 [3] 中捕获的) [6]:停止重写和处理新的 URL 和任何其他匹配的重写。
blog