Vanity URLs Should Redirect to a Canonical Route

Learn about the concept and significance of vanity URLs and their intended functions.

Why are canonical URLs not needed?

Like it or not, URLs are public-facing, so they are subject to the requirements of people outside the engineering team. Because they appear in search results, social media posts, and even podcast ads, we really need a way to make user-friendly URLs. But we don’t want to create a ton of inconsistency with the canonical URLs created by resources.

The way to think about this is that the canonical URLs we create with resources are for developers and should serve the needs of the team and app so that all the various URLs can be created easily and correctly. If user-facing URLs are needed, those should be created in addition to the canonical URLs and, of course, only if we need them.

Let’s suppose the marketing team is creating a big campaign about our widget collection, all based around the word amazing. They are initially going to buy podcast ads that ask listeners to go to example.com/amazing. The marketing team wants that URL to show the list of available widgets.

We don’t have that page yet, but we should not make the route /amazing the canonical URL for that page. For consistency and simplicity, we want a canonical URL, which is /widgets. Because we already have the resources call for the show action, we’ll modify the array we give to only: to include :index:

Get hands-on with 1200+ tech skills courses.