Nginx rewrite based on args

nginxrewrite

got links on old site like

/aaaa/bbbb/cccc.php?SECTION_ID=112233

So i need redirects based on value of SECTION_ID
for example /aaaa/bbbb/cccc.php?SECTION_ID=112233 leads to /aaaa/cccc/,

but /aaaa/bbbb/cccc.php?SECTION_ID=112244 leads to /aaaa/dddd/

I've ended up with

location /aaaa/bbbb/cccc.php {
    if ( $args ^SECTION_ID=(112233) ) {
        rewrite ^.*$ /aaaa/cccc/?   permanent;
    }
}

But no luck, thanks in advance 🙂

Best Answer

I missed some tildes. This one works:

location ~ ^/aaaa/bbbb/cccc.php {
    if ($args ~ "^SECTION_ID=(112233)") {
            rewrite ^.*$ /aaaa/cccc/? permanent;
    }
    if ($args ~ "^SECTION_ID=(112244)") {
            rewrite ^.*$ /aaaa/dddd/? permanent;
    }
}
Related Topic