[英]How to merge two nginx rewrite rules into one?
nginx rewrite rule: nginx重写规则:
rewrite ^/([a-z]+)$ /?type=$1 last;
rewrite ^/([a-z]+)/page/([0-9]+)$ /?type=$1&page=$2 last;
can I merge these two rules into one? 我可以将这两个规则合并为一个吗?
Haven't tested it but something like this might work.. 尚未测试过,但类似的方法可能有效。
^/([a-z]+)/?(page/([0-9]+)|)/?
Edit : here's the full block: 编辑 :这是完整的块:
location ~ /(blog)/?(page/([0-9]+)|)/? {
default_type 'text/plain';
echo "$1";
echo "$2";
echo "$3";
}
Going to /blog produces 去/博客产生
blog
Going to /blog/page/3 produces 转到/ blog / page / 3会产生
blog
page/3
3
$3 will have the page number if it's been specified otherwise it will be empty. $ 3将具有页码(如果已指定),否则将为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.