Nginx 重写和 2 个参数 [英] Nginx rewrite and 2 parameters
本文介绍了Nginx 重写和 2 个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 apache 中有这个规则:
I have this rules in apache:
RewriteRule ^seccion/([^/\.]+)/?$ index.php?tipo=seccion&slug=$1 [L]
RewriteRule ^seccion/([^/\.]+)/pag/([0-9]+)$ index.php?tipo=seccion&slug=$1&page=$2 [QSA,L]
两者都很完美,但是在 nginx 中我有这个 2
Both work perfect, however in nginx I have this 2
rewrite ^/seccion/([^\?]+)$ /index.php?tipo=seccion&slug=$1 last;
rewrite ^/seccion/([^\?]+)$/pag/([0-9]+)$ /index.php?tipo=seccion&slug=$1&pag=$2 last;
第二个不起作用,只有参数一个起作用但实际上得到了'pay'和添加的页码,示例
The second one does not work, only parameter one works but actually gets the 'pay' and the page number added, example
http://example.com/seccion/sports/pag/4
%slug
得到:sportspag4
知道我做错了什么吗?
推荐答案
请试试这个配置(你的第二条规则应该是第一条,就像在一个例子中):
Please try this configuration(your second rule should be first, like in an example):
rewrite ^/seccion/([^/]+)/pag/([0-9]+)$ /index.php?tipo=seccion&slug=$1&pag=$2 last;
rewrite ^/seccion/(.*)$ /index.php?tipo=seccion&slug=$1 last;
这篇关于Nginx 重写和 2 个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文