How to set a default controller if no other routes match
Go to /admin/config/system/site-information and set Default 404 (not found) page to the path of your custom controller.

In the controller place a typecasted $request in the argument list. Then get the path from the request and either build a custom 404 response or redirect to another page:

use Symfony\Component\HttpFoundation\Request;

  public function myController(Request $request) {
    $path = $request-&gt;getPathInfo();
    if ($path === '/abc') {
      return ['#markup' =&gt; 'Path "abc" does not exist!'];
    }
    else {
      return $this-&gt;redirect('&lt;front&gt;');
    }
  }




To answer the deleted comment. The controller can't set a status code 200, because it responds to a sub request and the master request is set to 404 no matter which 2xx status you set in the controller. For this you need an event subscriber: Does not redirect in EventSubscriber.