
When building a website, friendly URLs (also known as human-readable URLs) are very important. They improve SEO, make navigation easier, and help users understand the content before clicking.
https://myblog.com/posts/how-to-make-friendly-urls
https://myblog.com/posts/12345
Search engines use URLs to understand what a page is about.
A clear and descriptive URL helps search engines index your content better and can improve ranking.
Users can read the URL and immediately know what the page is about.
This builds trust and increases click-through rates.
Friendly URLs are easier to share on social media, chats, or emails.
Readable URLs are easier for developers to debug, remember, and manage.
I usually combine a readable slug with a short unique ID.
This keeps the URL clean while avoiding duplicates.
import slugify from "slugify";
import { nanoid } from "nanoid";
const title = "How to Make Friendly URLs in Next.js";
const slug = slugify(title, { lower: true, strict: true });
const id = nanoid(5);
const url = `/posts/${slug}-${id}`;
console.log(url);
// /posts/how-to-make-friendly-urls-3fX9k
const title = "Learn Next.js fast & easy!";
const slug = slugify(title, { lower: true, strict: true });
console.log(slug);
// learn-nextjs-fast-easy