URLs for blogs & personal websites

Published

You are about to create a blog or personal homepage with WordPress or a static site generator like Astro, and you need to decide how you will address your content. You already have a domain name. But what should the URL path to your articles or posts be?

  • /2024/09/urls-for-blogs
  • /2024/09/07/urls-for-blogs
  • /2024/urls-for-blogs.html
  • /urls-for-blogs.html
  • /blog/2024/urls-for-blogs.html

Slugs

Everything after the domain name is called the URL path (e.g. https://domain.com/path). The path identifies the content or page on your website domain. It typically contains keywords and phrases separated by hyphens, helping users and search engines understand the page’s subject or content. Because of the hyphens, many CMS call the path a slug. The slug is usually created from the title of the page or article. So, if this page’s title is “URLs for blogs & personal websites,” then the slug would be urls-for-blogs-personal websites. Note that a URL path can’t contain all the characters1 — only ASCII characters. However, URLs cannot contain spaces. URL encoding typically replaces a space with a plus (+) sign or a hyphen (-) or with %202. Using a hyphen (-) in a URL to separate words is recommended by Google SEO documentation.

Picking a slug from the title is nice, but it comes with some consideration. What do you do with translations? What happens when you change the title? Nonetheless, readable slugs are an excellent and convenient choice. An alternative could be to use a counter or an ID for your posts. For example, the path for your first post is /1, and the path to your second post is /2. You can foresee how finding which one will become challenging.

End slash or no end slash

Sometimes, you might see a URL path ending with a slash /. We call that a trailing slash. A bit of history. In the old times, a Web server would serve a folder of files on the Internet. A folder called urls-for-blogs with an HTML file called index.html would be available at /urls-for-blogs/. The file index.html is a particular case, it’s the default file shown when accessing a folder. A file called pages/about.html would be available at pages/about.html.

To simplify, a trailing slash indicates a folder. However, this is not so true anymore, as URLs can be rewritten and redirected with modern servers. Ultimately, I prefer not to use trailing slashes and have redirects (e.g., /things/ always redirects to /things).

Dated URLs

What about adding the year or month to the URL?

  • /2024/09/urls-for-blogs
  • /2024/09/07/urls-for-blogs

Dated folders are a nice option for a “real” blog, a place where you write daily, like in a diary. I don’t like the constraints of remembering which date a post was written, and it makes updating the post problematic. Adding a date will fix the article in time. What happens when you update it or rewrite it?

To .html or not to .html?

/blog/urls-for-blogs.html

Appending .html looks cool and has a 90s Internet vibe to it. It suits static content quite well because it says what it is: a plain HTML file that the browser will render. I prefer not to use .html because it takes longer to type the URL.

Using a category in the URL

You might be tempted to prefix the URL with a category name.

  • /blog/urls-for-blogs
  • /adventures/nakasendo
  • /book-reviews/the-little-prince

That’s fine. But you often want to change the name of a category, or the thing you wrote belongs to many categories.

Conclusion

I prefer to use a unique slug of words separated by hyphens (-) and only ASCII characters. It doesn’t have to be the same as the article or post title. It can be something memorable. So, for example, if you write something on procrastination, use domain.com/procrastination. If you want to point someone to an article you wrote, the URL will be easy to remember. The slug is a unique identifier on your domain for your page, article, or blog post. I also name the folder where I keep the Markdown file the same as the slug, which makes finding things easier.

Footnotes

  1. https://datatracker.ietf.org/doc/html/rfc3986#section-3.3

  2. Percent encoding