【问题标题】:Nginx rewrite rules not working / being ignoredNginx 重写规则不起作用/被忽略
【发布时间】:2013-12-25 05:05:30
【问题描述】:

我目前正在尝试重写:

index.php?page=Example&paramX=1&paramY=2

index.php/Example/1/?paramY=2

但是,这不起作用:

rewrite ^index\.php/\?page=Example&paramX=([0-9]+)&paramY=([0-9]+)$ /index.php/Example/$arg_paramX/?paramY=$arg_paramY permanent;

在apache2中,我目前使用

RewriteCond %{QUERY_STRING} page=Example&paramX=([0-9]+)&paramY=([0-9]+)
RewriteRule ^index\.php$ /index.php/Example/%1/?paramY=%2 [R=permanent,L]

这是有效的。

【问题讨论】:

    标签: apache .htaccess nginx rewrite


    【解决方案1】:

    你不能在 nginx 中匹配查询字符串参数,你必须尝试使用​​ if 之类的东西检查各个参数:

    location /index.php {
       if ($arg_page = "Example") {
          rewrite ^ /index.php/Example/$arg_paramX/?paramY=$arg_paramY permanent;
       }
    }
    

    如果您绝对需要验证 paramXparamY[0-9]+,那么您需要对嵌套的 IF 语句进行某种破解,例如 this

    【讨论】:

    • 那么除了多个规则的多个 if 语句之外,没有别的办法了吗?
    • @user2368182 如果要与查询字符串匹配,则不要
    猜你喜欢
    • 1970-01-01
    • 2013-02-24
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    • 2018-11-13
    • 1970-01-01
    • 2012-04-24
    • 1970-01-01
    相关资源
    最近更新 更多