Do you mean like this ?
```
if (($uri = $router->getRequestUri()) && ($path = $uri->getPath())) {
    $sep = (false === strpos($url, '?')) ? '?' : '&';
    $url .= $sep . 'redirect=' . urlencode($path);
}
```