I figured out a solution that works for me. In the beforeDispatch() method of my FrontControllerInterface plugin, I have the following block of code:

    $requestPath = $this->request->getPathInfo();
    
    // If a coupon code was included in the URL, fix the URL
    // after extracting it so that we can continue to route normally
    if (preg_match("#/discount/([^/]+?)/*$#", $requestPath, $matches)) {
    
    	$coupon = $matches[1];
    	$realPath = str_replace($matches[0], '', $requestPath);
    
    	if (!$realPath) {
    		$realPath = '/';
    	}
    
    	$this->request->setPathInfo($realPath);
    }

This does exactly what I need. Hope it can also help someone else in the future.

EDIT: My plugin can be found here: [https://github.com/crankycyclops/DiscountCodeUrl][1] It's free and open source. Hope someone finds it useful :)


  [1]: https://github.com/crankycyclops/DiscountCodeUrl