I'm currently migrating our project to symfony2. In our current codebase, we have a mechanism that allows us to define routings in a database table. We basically specify a regex the request URL gets matched against, and specify the URL the user should be redirected to. This redirecting works as a "last resort" right before throwing the 404. That way, these redirects never overwrite URLs that match existing actions and the matching is done lazily, only in case a 404 would have been thrown.
Is there a way to hook into Symfony's event model and listen for the NotFoundHttpException to do exactly that (e.g. issuing a 301/302 redirect if the URL matches some regex, instead of letting the 404 trough)?
As you can see from this cookbook page, a "kernel.exception" event is fired whenever an exception is thrown. I'm not aware of there being a specific event for a NotFoundHttpException but I'd suggest creating your own listener service for all exceptions and then checking within the service for the type of exception and adding your custom logic.
(Note: I haven't tested this, but it should at least give you an idea of how this can be achieved.)
Configuration
Listener service