Nginx重写和2个参数
我在apache中有以下规则:Nginx重写和2个参数,nginx,Nginx,我在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 rewrite ^/seccion/([^\?]+)$ /index.php
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
rewrite ^/seccion/([^\?]+)$ /index.php?tipo=seccion&slug=$1 last;
rewrite ^/seccion/([^\?]+)$/pag/([0-9]+)$ /index.php?tipo=seccion&slug=$1&pag=$2 last;
第二个参数不起作用,只有参数1起作用,但实际上得到了“pay”和添加的页码,例如
http://example.com/seccion/sports/pag/4
%slug得到:sportspag4
你知道我做错了什么吗?在你的第二条重写规则中有一个额外的美元符号,它匹配行尾并终止匹配。此外,您的第一个重写规则当前正在匹配所有内容,它应该位于第二个规则之后,或者在匹配中更加严格。试试这个:
rewrite ^/seccion/([^/]+)/?$ /index.php?tipo=seccion&slug=$1 last;
rewrite ^/seccion/([^/]+)/pag/([0-9]+)$ /index.php?tipo=seccion&slug=$1&pag=$2 last;
请尝试此配置您的第二条规则应为第一条,如示例所示:
rewrite ^/seccion/([^/]+)/pag/([0-9]+)$ /index.php?tipo=seccion&slug=$1&pag=$2 last;
rewrite ^/seccion/(.*)$ /index.php?tipo=seccion&slug=$1 last;
好的,看起来第一条重写规则捕获的内容太多了。我已经相应地更新了,试一试。