Developer workflow

How to Prevent Duplicate URL Slugs in a CMS

Find slug collisions, enforce uniqueness, and distinguish duplicate paths from duplicate content.

Photorealistic editorial photo for Duplicate Url Slugs
Developer workflow · Practical ideas for your next build

Duplicate slugs can make two records compete for one route. They are a routing and data-integrity problem even before search indexing becomes relevant. A robust CMS checks uniqueness in the same scope used by its router, then stores a stable public address for each record.

Define the uniqueness scope

Some sites require a globally unique slug. Others include locale, content type, category, or a parent path. A slug named introduction may be valid under two different documentation sections but invalid twice under the same parent. Make the database uniqueness constraint match that routing model. A UI check alone can race when two editors publish at the same time.

Normalize before comparing

Apply the same case, separator, accent, and trailing-slash rules during generation and validation. Different titles can collapse into an identical candidate after normalization. Our list generator reports duplicate line numbers instead of appending arbitrary suffixes. Resolve them with editorially meaningful names or stable identifiers, then check against existing records. Handle empty output explicitly, particularly for titles containing unsupported scripts or only punctuation.

Keep slugs stable after publication

Changing a title does not always justify changing its URL. Store the published slug separately and use redirects when a deliberate rename is necessary. Duplicate content is a different concern: two distinct URLs can show the same article even if their slugs differ. Choose one canonical address and keep internal links and sitemaps consistent. Canonical hints do not replace route uniqueness or a reliable redirect after a move.

Worked example

EXAMPLE
Red Shoes → red-shoes
Red-Shoes → red-shoes
Resolve before publication; do not overwrite either record.

Can canonical tags fix two records sharing one route?

No. The router and database must identify one record per path. Canonical tags address preferred URLs for accessible pages.

Reference and further reading

Read the official documentation ↗