Is there a way to have server-side code handle the case when a URL doesn’t match an existing route (404 NotFound) and can send a server HTTP 301 redirect before rendering the frontend?
The full story: I’m building a simple short links/golink type service where user’s can register short names for longer URLs. For example, mydomain.com/EmployeeHandbook would redirect to a much longer URL, like a google doc.
In a perfect world, there would be a catch-all route which would look at the URL, see if the path matches a record in the DB and to the longer URL. If not, it would render the form to create a new short URL.
In an even more perfect world, the short name could include path sections. For example: mydomain.com/Eng/Standards. This would likely break the default routing patterns.
Using the NotFound route seems like a natural fit, but it seems like it’s still run in the browser. Is there any way to ensure this happens on the server-side?