Symfony default, catch-all route for non-existent URLs

Symfony’s routing system is pretty easy to understand, however, what happens when you need a default, catch-all route that doesn’t match any other routes?  Instead of sending a customer to a 404, you can redirect them to a default path, in this case, it’s the root path “/” (defined in the line “path: /” below) but it could be another path if you’d like.  Remember that the order of the routes are important and take precedence over ones Symfony encounters later down the routing directives list.

    path:     /{path}
        _controller: FrameworkBundle:Redirect:urlRedirect
        path: /
        permanent: true
        path: ".+"

Visit Symfony’s documentation for more details:

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

Your email address will not be published. Required fields are marked *