Spotlight Pathauto

Magic Submitter

Instant Linkbuilding Solutions

Get Instant Access

In Chapter 2, you learned about the Drupal path and how to use clean URLs. One reason to use clean URLs is so that they don't look so ugly. (To review, clean URLs remove the "?q=" from the URL.) That helps, but still leaves the URLs lacking a bit. Having a URL with "node/123" in it doesn't really tell either humans or search engines much about the page itself. Isn't it much better to instead have a URL with something like "about-us" in it? That is going to be much more memorable for a person, and the addition of pertinent keywords in the URL makes for better search engine optimization. So, even without clean URLs, you can still benefit from good pathnames.

We'll quickly review the core Path module that we mentioned in Chapter 2. When enabled, it will add a new fieldset to the node creation/editing form called "URL path settings," as shown in Figure 5-9. When you expand that fieldset, you will have a field in which to enter an alternative name for that node's path (called a path alias). The name that you enter here will be used in place of the Drupal path, the part of the URL that comes after (or if you don't have clean URLs enabled).

i- t URL path settings-

Optionally specify an alternative URL by which this node car be accessed. For example, type "about" when writing an about page. Use a relative path and don't add a trailing slash or the URL alias won't work.

- ►Authoring information

Figure 5-9. The Path module's settings fieldset on a node edit form

This field is a huge help, but it can be somewhat tedious to enter all of those names by hand if you are creating a lot of content. Also, if you have many users making content, you need to make sure that they all understand this and use consistent naming throughout the site, which can be an administrative headache. Another limitation of the Path module is that we get that handy alias box only on nodes. What about things like user profiles or vocabulary paths?

As often occurs in Drupal, contributed projects provide us with a module that deals with this issue. Enter the Pathauto module. As its name implies, it creates automatic path aliases for nodes, taxonomy, and user paths. Pathauto is dependent upon the core Path module and another module called Token, discussed in the sidebar.

What Is a Token?

Tokens are placeholders. For example, [yyyy] represents a four-digit year, and [author-name] represents the username of a node author. These are made available to Drupal through the Token module. The Token module is different from most modules that you use on a site in that it provides functionality that is not directly visible to administrators or site users. It needs other modules, like Pathauto, to provide an interface. The Token module creates a central repository of placeholders. Modules that have data (like the core Node module, which knows the date a node was created) can let Token know they have something to share. You can think of these as "suppliers." Modules that want to use that data, like Pathauto, can tap into the list of what is available. These are more like "consumers." Token acts like a storefront that can sell various things that the suppliers bring in to the customers who want to consume them.

The Token module itself provides some basic placeholders that are available by default on behalf of Drupal core modules, notably for content types (the Node module), vocabularies (the Taxonomy module), and users (the User module). Contributed modules can become "suppliers" as well by providing new placeholders that represent data that they know about. They just need to speak Token's language and say "Hey, I have this xyz bit of data in the database and you can tell others about it by telling them to use the [xyz] placeholder."

Pathauto uses a combination of plain text and "tokens" to set up URL naming patterns for the module to follow. For instance, you can set up a pattern for naming the path of all new blog pages to be "blog/[yyyy]/[month]/[date]/[title-raw]" so that you automatically get something like "blog/2007/june/08/my-first-blog-post." Figure 5-10 shows the automatic alias set by Pathauto for a wiki page, titled "Help," which is using the pattern "wiki/[title-raw]."

t URL path settings Automatic alias

A/i alias will be generated for you. If you wish to create your own alias below, untick this option. To control the format of the generated aliases, seethe Pathauto settings.


Figure 5-10. Pathauto's version of the path settings on a node edit form with a path automatically prefilled

Figure 5-10. Pathauto's version of the path settings on a node edit form with a path automatically prefilled

The parts of the pattern in square brackets are placeholders for the Token module mentioned earlier. You can create these patterns for each unique content type or vocabulary if you choose. Pathauto also has configurable default patterns that will be applied if you don't make specific ones. Pathauto lets you decide things like how long your alias is allowed to be, what kind of separator you would like to use in the place of spaces or punctuation, and which common, short words you want to remove (e.g., a, and, in, etc., and so on). In addition to making these automatic aliases upon creation of new content, Pathauto can also update all of your existing content so that your entire site uses the same pattern, even if it was created prior to using Pathauto.

One important thing to consider when using Pathauto is how you want to manage changing your aliases. Because the alias is created based on information that Pathauto is getting about that content, if you update the content you can change your alias. You can decide what you want to do when you make updates. You can:

• Do nothing. Leave the old alias intact.

• Create a new alias. Leave the existing alias functioning.

• Create a new alias. Delete the old alias. (This is the default.)

Different sites may have different reasons for choosing which option they want to use. The default is to make a new one and delete the old so that your aliases always match your content. This option can be problematic in that it can cause link rot. Link rot happens like this: you have a certain URL on your site, such as about, and other sites on the web create links pointing to that URL. If you change that URL to and delete the old one, all of those outside links will stop working. That's link rot.

The second option, making a new alias and keeping the old one, may sound ideal, because you then access the content from either path and the problem of link rot is eliminated. But, while addressing the issue of link rot, the disadvantage of this option is that some search engines will penalize you for having many paths that point to the same page because they think you may be trying to game the search results. One way to get around this issue is to use the Path Redirect module ( path_redirect) with Pathauto. When you use the Path Redirect module, you will see a fourth option for setting your alias: "Create a new alias. Redirect from old alias." Using this option automatically redirects incoming links that are using the old URL to the new URL.

Look over the Pathauto settings and play around with them while your site is under development to determine the best fit for your site's needs. Once the site has been launched and people are using it, avoid making any major change to your Pathauto settings, as users may come to depend on the URLs behaving in a particular way.

Was this article helpful?

0 0
Link Wheels for Dummies

Link Wheels for Dummies

The only thing you need to start a link wheel is CONTENT Articles and the mentioned pages at your money site to link to. But like anything in IM, building a link wheel is not an exact science. Feel free to build the link wheel the way it suits you. Learn more within this guide by downloading it today.

Get My Free Ebook

Post a comment