Nginx Rewrite Convert Querystring to Path

If you want redirect

location ~ /somefolder/mypage.aspx {
    if ($args ~* "^myid=(\d+)&tab=overview") {
        set $mid $1;
        set $args '';
        rewrite ^.*$ /folder/$mid/overview permanent;
    }
}

Don't forget to configure /folder/$1/overview location.


A shorter and more correct version of Valery Viktorovsky answer.

location = /somefolder/mypage.aspx {
    if ($arg_tab != overview) { return 404; }
    if ($arg_myid !~ "^\d+$") { return 404; }
    rewrite ^ /folder/$arg_myid/overview? permanent;
}

Or, hey, it can even be shorter, if you don't need to be verifying the arguments:

rewrite ^/somefolder/mypage.aspx /folder/$arg_myid/$arg_tab? permanent;