[英]Nginx rewrite rules not working / being ignored
I'm currently trying to rewrite this: 我目前正在尝试重写此代码:
index.php?page=Example¶mX=1¶mY=2
to 至
index.php/Example/1/?paramY=2
However, this isn't working: 但是,这不起作用:
rewrite ^index\.php/\?page=Example¶mX=([0-9]+)¶mY=([0-9]+)$ /index.php/Example/$arg_paramX/?paramY=$arg_paramY permanent;
In apache2, i currently use 在apache2中,我目前使用
RewriteCond %{QUERY_STRING} page=Example¶mX=([0-9]+)¶mY=([0-9]+)
RewriteRule ^index\.php$ /index.php/Example/%1/?paramY=%2 [R=permanent,L]
which is working. 这正在工作。
You can't match query string parameters like that in nginx, you've got to try to check the individual arguments using something like an if
: 您无法匹配nginx中的查询字符串参数,必须尝试使用诸如
if
方法来检查各个参数:
location /index.php {
if ($arg_page = "Example") {
rewrite ^ /index.php/Example/$arg_paramX/?paramY=$arg_paramY permanent;
}
}
If you absolutely need to verify that paramX
and paramY
are [0-9]+
, then you'll need to do some sort of hack for nested IF statements, something like this . 如果您绝对需要验证
paramX
和paramY
为[0-9]+
,则需要对嵌套的IF语句进行某种修改 ,例如:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.