Create a stable URL for content using an ID

Sorry if this has already been discussed, I find it extremely hard to find anything on this kind of forum, especially if you’re not sure what keywords to look for…

I was wondering what would be considered best practice when you need a stable URL for your data. In most examples on Contentful the slug seems to be used as an identifier, like example-com/news/this-is-my-article. But this means that whenever someone changes the title (in case of a typo for example) the link will change and the old one becomes a 404.

I’d rather use some sort of ID in the URL and only add the slug as a visual cue for users, so both

example-com/news/421/this-is-my-article
and
example-com/news/421/xxxx

would point to the article with ID 421.

Problem here is that the unique ID generated by contentful looks like 28Bz7NkSvkrjuls9Wy9tyB which wouldn’t look very attractive in the URL. Is there a way to use a numeric ID that is unique, but also more pleasing to the eye?

1 Like

You could create your own Contentful plugin that adds a special slug input to your posts. I did think to do this, but I did not yet did this. And the project I was using Contentful for is stale

I think creating my own plugin would hardly be considered best practice :wink:

1 Like

Well, at least you have full control over what your slug looks like and what you want to do with it.