Building a Programmers Blog: Friendly URLs

According to the experts in search engine optimization (SEO), it is quite important that your site URLs are informative and well structured. The Drupal defaults leave something to be desired in this area. Fortunately, Drupal provides easy support for improving your URL structure.

For example, a typical Drupal URL looks something like this:

http://www.example.com/?q=node/123

Using clean URLs that don't contain parameters (marked by the ? delimiter) is a good starting point, and something automatically used by Drupal 6 if possible. See Clean URLs from the Drupal Installation guide for more information.

Beyond this, however, there are a number of improvements you can make using the Path and PathAuto modules.

Path allows you to manually define custom URLs for any piece of content on your site. This module is included in core and will already be available for you, awaiting activation.

PathAuto provides automation for Path, defining custom URLs for every piece of content as they are written. This module is included in some distributions, but not in core - you may need to download and activate it yourself. (See Module Installation for more.)

After activating both Path and PathAuto, the next step is to configure the Pattern to use for each node type.

Ensured you're logged onto your Drupal installation as an administrator, go to Administer, Site building, URL aliases and select the Automated alias settings tab.

Under Node Path Settings you'll find space for a separate pattern for each node type. These patterns are filled in with a combination of literal text and replacement patterns enclosed in square brackets. There are a large number of possible replacement patterns available, all listed under the Replacement Patterns heading.

Some of the more useful replacement patterns include:

  • [nid] - the unique node id number
  • [title-raw] - Unfiltered node title
  • [yyyy] - Node creation year
  • [mm] - Node creation month

For blog entries on our blog, let's use the following pattern:

blog/[yyyy]-[mm]/[nid]/[title-raw]

This groups blog entries by their month of publication, includes the node title in the URL (useful for SEO), and includes the node id itself.

Similarly, for pages lets use the following pattern:

page/[nid]/[title-raw]

Again, this retains both the [nid] (useful for us) and the node title (useful for SEO).

Some tips for good path alias patterns:

  • Do include [nid].
    I used to have a pattern that didn't include the node id, but found that there are enough times when knowing the node id is useful that changing the pattern was worthwhile.
  • Always start with a constant prefix that doesn't collide with any Drupal reserved path.
    If an alias happens to match a Drupal reserved path, you can end up blocking access to that function entirely. For more information see Drupal PathAuto Tutorial and Pathauto Patterns that can be Dangerous.

Comments

SEO-friendly URL paths

This tutorial appears informative and includes vital codings which developers can use to forge website URLs . Creating a friendly URL is a tough task for developers since, search engine optimized websites aim for static URLs, omitting special syntax that could hinder the process of website indexing. URLs should not appear cumbersome, if your website is a blog then, the word ‘blog’ should appear in the URL, along with the year and the title of the story. I could use more of these tips, by the way.