Stackoverflow might be doing some fancy URL rewriting. A simple way to do this is to send a redirect. Have your handler method get the the user id and check if it matches the user name string. If it doesn't, then send a redirect
return "redirect:/users/" + id + "/" + correctUserName;
This will send a 302 response to the browser. The browser will send a new HTTP request to the constructed address.