nginx: selectively stripping URL params

rewrite (as well as location) nginx directives works with so-called normalized URI which is not included the query part of request (other normalization steps includes decoding the text encoded in the URL-encoded “%XX” form, resolving references to relative path components “.” and “..”, and possible compression of two or more adjacent slashes into a single slash). You should change $args nginx variable instead. Using your regex it would look like

if ($args ~ ^(.*)(&?_sm_byp=\w+)) {
    set $args $1;
}

Change from [&?] to &? isn't a mistake. It is made because $args variable does not include the question sign, so & character can be present if _sm_byp query argument isn't the only one or can be absent otherwise.

I can suggest more advanced regex (authored by myself) which allows to cut some query argument from the query string no matter it is at the beginning, in the middle or at the end of that string:

if ($args ~ (.*)(^|&)_sm_byp=[^&]*(\2|$)&?(.*)) {
    set $args $1$3$4;
}