Pathauto and Multi-level Site Sections

Have you ever needed to automatically create a URL with a structure like the one below?

There are a couple ways to accomplish this. The first step is to install the Pathauto and Tokens modules. You might need a couple more depending on which strategy you choose to use. Below are several strategies you can use to accomplish this requirement.

Taxonomy Term

If you only have one level to your URL structure, you can use a vocabulary.

  1. Start by creating a vocabulary called Section (or anything you want).
  2. Make sure the Section vocabulary is weighted to always be the first vocabulary that appears on your add/node interface.
  3. Add terms that represent your site sections.
  4. Go to site building>URL aliases>automated alias settings
  5. Configure the node path settings:
  6. If the vocabulary is not required and not selected, the path defaults to [title-raw]

Text Fields

With the CCK textfield option, you can make a series of text select fields. Create a field for each section / sub-section level of your site.

  1. Start by installing CCK module and enable the text field.
  2. Go to content management>content types>edit page (or whatever CT you want to add the fields).
  3. Create a field for each section and sub-section you need and insert the applicable section and sub-section text you need.
  4. Go to site building>URL aliases>automated alias settings
  5. Configure the node path settings something link this three levels:
  6. If the fields are not required, the path defaults to [title-raw] if nothing is selected.

Content Taxonomy Field

This combines the first option with the second option. Instead of using the text field to create a select list, you use the Content Taxonomy field module and make your list by populating a series of vocabularies (section, sub-section-one, etc.), one for each level you need and for each field you create.

The path would look similar to the text field sample above:

Hard Code

Don't cringe! There are times when it is more convenient to simply hard code the terms you want for the path. For example, let's say you have a content type for each section of your site (news, events, projects). You could set each content type to have it's own path.

  • news/[title-raw]
  • events/[title-raw]
  • projects/[title-raw]

Combination of the Above

Like with a lot of features in Drupal, you can use a combination of the above. For example:



You have other options with Pathauto of course. For example, you can use [term-raw]/[book-raw]/[title-raw] when you want your book pages to appear with the book's first page. The challenge comes when you need custom site sections. Hopefully this gives you some options.