Alias content

Last modified: September 19, 2007 - 07:15

In this example you will learn how to activate a module, check for permissions and alias the URL path.

By default, a typical Drupal URL will be www.example.com/?q=node/3 or www.example.com/node/3. While this is useful, Drupal core comes with a module that can make it nicer.

  1. Navigate to Administer > Site building > Modules
  2. In the core options module list locate Path module.

    Note the description “Allows users to rename URLs.

  3. Select the box next to it and select save configuration on the bottom.
  4. Navigate to Administer > User management > Access control

    Note

    Many modules add features which often will need to be assigned to your sites roles. By default new features are not enabled for any role. UID1 has access to all your sites features.

  5. Scroll down to the path module entry. You will see two new permissions
    administer URL aliases - this allows an administrator to edit/update aliases
    create URL aliases - this allows users to alias nodes
  6. Choose the role you wish to grant this ability to and then select save permissions
  7. You can either create new content or edit a previously created node.
  8. Scroll down on the edit page and find the collapsed fieldset URL path settings.
  9. Enter an alias for your content and submit your page.

    For this example we'll use test-alias

  10. You should now be able to browse to your content at www.example.com/test-alias
  11. Browse to Administer > Site building > URL aliases.

    This is where you can edit and add multiple aliases to content. Select the more help... link for some examples of how to alias other Drupal URLs.

Adjust relative URLs to files & images when using path aliases

authentictech - August 15, 2008 - 13:25

Note that if your path alias includes more than one path element (e.g. story/pets/kittens ) each path element will be treated as a directory by Drupal; therefore, when linking to files and images in your content you should adjust the relative URL to your files accordingly.

So, for example, if the relative URL to your image (without using the alias) is:

sites/default/files/kitten.jpg

when using the alias in the example above you will have to use the URL:

../../sites/default/files/kitten.jpg

to account for the additional directories in the path alias.

You should be particularly aware of this if you are using the pathauto module as you may not always be aware of what path will be automatically created for your content as set in the pathauto module settings.

 
 

Drupal is a registered trademark of Dries Buytaert.