Last updated March 9, 2014. Created by ff1 on September 11, 2004.
Edited by batigolix, Delphine Lepers, Heine, choster. Log in to edit this page.

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 :

  • Set the path for an individual node with the Path module (on the node/add or node edit form).
  • Add a URL alias at Administer > Configuration > Search and metadata > URL aliases in Drupal 7, Administer > Site building > URL aliases > add alias in Drupal 6.
  • Administer the list of URL aliases at Administer > Configuration > Search and metadata in Drupal 7; Administer > Site building > URL aliases in Drupal 6.

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 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, penalises 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. Perhaps the simplest solution is to use the Path Redirect (Drupal 6) or Redirect (Drupal 7) modules to create the redirects automatically.

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 (Administer > Site building > Modules in Drupal 6). 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 in Drupal 7 (Administer > Site building > URL aliases in Drupal 6), 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 (Administer > User management > Permissions in Drupal 6), 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 retreive the path in your programming code using the function drupal_get_path_alias(), for example as follows.

$path = drupal_get_path_alias('node/1')

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

I succeeded to change links from:

"How to Get Only Major Words in the Articles Title?"
http://DrupSite.org/node/27

To: http://DrupSite.org/27/only-major-words-articles-title

Steps in "url-aliases" (admin section of autopath);

* add a lot of non-important short words in the general configuaration to filter in the title, include all single letters, but don't include numbers;

* be sure to have changed the file name to i18n-ascii.txt in the i18n module; failing this lets disappear letters like é, ñ, ö, ... etcetera, causing breaking of words in titles;

* use the form [nid]/[title-raw] what means: yoursite.org/nodeID/modified title.

Then with a change in .htaccess (within the rewrite rules section) the article title can regenerate itself with only the article-number:

RewriteRule ^([0-9]+)$ node/$1/
(the last "/" is not an error, it works faster and with less errors at my install)

Now if someone doesn't have the proper title-link anymore (broken or whatever), just skinning it down to:
http://DrupSite.org/27 ,or
http://Drupsite.org/27/
=> will change it for the ..../node/27 original title, what is then changed inmediately for the external and complete official title.

Then it must be possible to intercept broken links, having the broken link automatically skinned down to only the page number = nid(nodeID) page-number. Preferably this only should be done on broken links and not as a general rule for all links. The latter is more easy, because that would be some other general RewriteRule in .htaccess just before the mentioned rule.

But I have no idea what further code should be used and where??!

(all my work here was just checking info and experimenting over 10 hours untill I got it working without knowing these codes)

I'm writing a custom search module.

I can get the parameters from the url easily by using the function: arg()

http://mysite.com/node/3/key+word
.arg(0) -> 'node'
.arg(1) -> '3'
.arg(2) -> key+word (So i can work with this later)

But when i added an alias like below
http://mysite.com/node/3 --> http://mysite.com/search (the http://mysite.com/node/3 is my search page)

Then I can't get the keyword when reading http://mysite.com/search/key+word
.arg(0) -> 'node'
.arg(1) -> '3'
but .arg(2) -> null

Do you have any ideas for this problem.
Thank you so much.

I am getting a problem with paths, I have the path and clean URLs modules installed when you first go to the site you get www.example.co.uk/home you can click on an other navigation and get a shortened name ie: www.example.co.uk/about or www.example.co.uk/login but after the second you have clicked on the second page it goes back to the long URL showing all the folders from where it is hosted to the final page. I can not seem to change this anyone have any ideas?