Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Clean URLs

Definition

Clean URLs, also known as user-friendly URLs, pretty URLs, search engine-friendly URLs, or RESTful URLs, are web addresses (Uniform Resource Locators or URLs) designed to enhance the usability and accessibility of websites, web applications, or web services. They aim to be immediately meaningful to non-expert users, reflect the logical structure of information, and decouple the user interface from the server’s internal representation.

Benefits

  • Improved usability and accessibility for users.
  • Enhanced search engine optimization (SEO).
  • Conformance with the representational state transfer (REST) architectural style.
  • Consistency in web resource locations, facilitating bookmarking.
  • Reduced difficulty in changing the resource implementation, as clean URLs don’t contain implementation details.
  • Improved security by concealing internal server or application information.

Structure

Clean URLs typically consist of a path that represents a logical structure that users can easily understand. They avoid including opaque or irrelevant information such as numeric identifiers, illegible data, or session IDs found in query strings.

Examples

  • Original URL: http://example.com/about.html Clean URL: http://example.com/about
  • Original URL: http://example.com/user.php?id=1 Clean URL: http://example.com/user/1
  • Original URL: http://example.com/index.php?page=name Clean URL: http://example.com/name
  • Original URL: http://example.com/kb/index.php?cat=1&id=23 Clean URL: http://example.com/kb/1/23
  • Original URL: http://en.wikipedia.org/w/index.php?title=Clean_URL Clean URL: http://en.wikipedia.org/wiki/Clean_URL

Implementation

The implementation of clean URLs involves URL mapping through pattern matching or transparent rewriting techniques on the server side. This ensures that users primarily interact with clean URLs.

For SEO, developers often include relevant keywords in clean URLs and remove unnecessary words, enhancing user-friendliness and search engine rankings.

Slug

A slug is the part of a URL that contains human-readable keywords identifying a page. It typically appears at the end of the URL and serves as the name of the resource. Slugs can be automatically generated from page titles or entered manually.

Characteristics of Slugs

  • Often entirely lowercase.
  • Accented characters replaced by Latin script letters.
  • Whitespace characters replaced by hyphens or underscores.
  • Punctuation marks removed.
  • Some common words (e.g., conjunctions) may be removed.

Slugs provide a brief idea of a page’s topic, help organize long lists of URLs, and make filenames more descriptive when saving web pages locally.

Websites using slugs include Stack Exchange Network and Instagram for question titles and user-specific URLs.