Path module overview

Last updated on
21 November 2016

The core Path module lets you optionally create URL aliases for your Drupal pages. By default, Drupal automatically creates web addresses like http://www.example.com/?q=node/67, which are not user- or search engine-friendly. Search engines will give better rankings to pages that have more human-friendly URLs, especially if they include relevant keywords - for instance, http://www.example.com/?q=all-about-tarantulas.

Uses

As an administrator you can :

  1. Set the path for an individual node with the Path module (on the node/add or node edit form).
  2. Add an URL alias at Administer > Configuration > Search and metadata > URL aliases > Add alias
  3. Administer the list of URL aliases at Administer > Configuration > Search and metadata > URL aliases

When combined with using Drupal's "Clean URLs" feature http://www.example.com/?q=all-about-tarantulas becomes www.example.com/all-about-tarantulas, which is the ideal readable form.

Some examples of URL aliases:

  • image/tid/16 => store
  • taxonomy/term/7+19+20+21 => store/products/whirlygigs
  • node/3 => contact
  • node/10 => products/merchandise/cups
  • node/11 => coffeemakers

You can create URLs as many levels deep in your virtual directory structure as you like. So, for example, suppose a page is called http://www.example.com/taxonomy/term/7+19+20+21. You could give it an alias of www.example.com/store/products/whirlygigs

Tips about URL aliases

Avoid changing aliases

Although it is possible to assign the same internal URL to multiple aliases, this is generally not a good idea for search engine rankings; Google, for example, penalizes your site by dropping its rank if Google thinks that you are publishing duplicate content under multiple URLs (a form of web spamming). So if you change your mind later on and must change a URL alias, say from http://www.example.com/dangerous/tarantulas to http://www.example.com/beautiful/tarantulas, you don't want to just delete the old URL, or that page will have to start from scratch building up page rankings.

Redirect old aliases

In the case of a permanent change, use a "301 redirect" from the old URL to the new one. As with many things Drupal, there are several ways to do this, and the best solution will depend on the pattern and number of changes and your environment.

Use aliases from the start

Considering the above, it's best to enable the Path module and assign aliases to your content from the very start. Although batch URL aliasing is possible through several different mechanisms, you don't want to have to deal with the consequences of search engines and external sites already linking to your pages via the /node/xx URLs. Or, if you are converting a site over from another platform (blogging tool, standard HTML-CSS), create your aliases to match the URLs from the previous site. You'll carry all the search engine history right along to the new one.

How to use Path

Enable the path module on the modules page at Administer > Modules. When users with the right permissions create or edit posts, they'll see a field for "URL path settings." That's where they can enter an alias of their choice.

On the URL aliases page, at Administer > Configuration > Search and metadata > URL aliases, you'll see a list of all the URL aliases on your site. There you can edit them, and add new ones. You can assign more than one alias to a page (just use the add alias tab again for each new alias).

On the permissions page at Administer > People > Permissions (tab) in Drupal 7, you can decide who can create aliases and who can administer the list of them.

You should consider configuring clean URLs if supported by your server. To automate the generation of URL aliases, look into using Pathauto module.

Programmatically retrieve path

You can retrieve the path in your programming code using the function drupal_get_path_alias(), for example as follows.

$path = drupal_get_path_alias('node/1')