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,
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
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
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/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.
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')