URLs are a critical part of all web sites, not just Drupal. However, in Drupal, the URL of a page determines a lot about how the page is built.

A Uniform Resource Locater (URL) is simply the address of a particular page, what you see at the top of your browser starting with http:. In static web sites, a URL is simply a path to a file on a web server somewhere. In Drupal and in other content management systems and frameworks, a URL can be much more -- it can also contain a set of instructions for the program to run to generate something on the fly. Here's what you need to know about URL handling in Drupal.

Internal Paths

For most content items in Drupal, there are at least two different URLs to reach the item: the internal path, and one or more "friendly" or aliased URLs. The internal path to any item of content is node/<node id>. Add the domain name in front of this, and you've got a full URL. For example, this story has a node id of 407, so its internal path is node/407 and the full URL is http://freelock.com/node/407.

The Views module allows you to define arbitrary internal paths to any pages you create. About the only rule to paths provided by a view is that they take precedence over other paths that might be defined in the system--so the URL rules for views are very specific to an individual web site.

Other modules define other paths to generate particular pages. For example, the taxonomy module provides a path taxonomy/term/<term id>. If the site does not override this path with a view, you can see all content that's tagged with a particular taxonomy term with a link like http://freelock.com/taxonomy/term/13. Or you could if we hadn't rewritten that URL.

Most modules provide other internal paths to access settings pages and other pages they generate.

Friendly URLs, or Aliases

The Path module lets you create arbitrary paths to any internal path in the system, and combined with some clever rules in the Pathauto and Token modules, you can set up a site with an automatic URL scheme based on all kinds of different aspects of the content. These friendly URLs are also known as aliases.

One very common pattern we put in many sites is this: [vocab-raw]/[termpath-raw]/[title-raw]. What this does is it creates a URL structure based on how you tag an individual story. For example, you might have one taxonomy for Departments, and another taxonomy for Projects. These taxonomy names get converted to lower case and used as the first part of the URL, [vocab-raw]. The actual term you apply to a story becomes the second part, the [termpath-raw]. If you have a nested hieararchical taxonomy, this will add all the parent terms to the path for you. Finally, we use [title-raw] to convert the actual page title to something you can use in a URL. The end result is that instead of having a path like node/4493, we end up with department-owner/food-services/catering, a far more appetizing place to go. Search engines love friendly URLs like this, so they're often called "search-engine friendly" URLs.

You can use either an internal URL or an alias in block visibility settings. Aliases are particularly useful, however, since you can use a wild card to apply it to a lot of pages.

URLs for block visibility

So why is all of this important? Besides search engines, Drupal itself uses URLs for more than just which page of content to retrieve. The block system relies heavily on URLs, and can use either an internal path or a friendly URL to control whether a particular block appears on a page.

For example, if you want to create a sub-section of a site with a custom menu associated with a particular project, leveraging a clever URL scheme is one of the simplest ways of getting the job done. On the Bellingham School District site, for example, this is how the menu for the Culminating Project works. All pages that go into this section get tagged with the term "Culminating Project" from the "Projects" vocabulary. This gives each of these pages a URL that begins with projects/culminating-project/. And then in the block visibility settings for the Culminating Projects menu, we can simply show the menu only on pages that have the path projects/culminating-project/*.

Troubleshooting blocks and URLs

If you follow a link on a Drupal site and don't see the right combination of blocks, first take a look at the URL your browser is on. Then go to the block that's either appearing where it shouldn't, or not appearing when it should, and take a look at the block visibility settings to see if that path should be included or excluded. The fix might be as simple as correcting the block visibility settings.

It's also possible that another term took precedence, and so you've gotten a different URL for the page than you expect. With the automatic pattern we use, the friendly URL is generated from the first term and vocabulary it finds attached to the item, sorted by the order in the taxonomy module. So if a story has several terms applied, only one will be used to generate the path. If the wrong one is getting applied, you can drag the vocabularies and terms around to reorder them in the taxonomy manager.

Using Redirects

There's a very similar system for getting to content, called Path Redirect. Like the friendly URL system, it allows you to create custom URLs for particular internal paths. Unlike the alias system, you can have as many redirects as you want pointing to a given page.

An "alias" to an internal path essentially replaces the internal path. Under most circumstances, you'll only see the friendly URL when you visit a page, regardless of how you got there. A redirect is mainly a way to preserve old links. In general, search engine experts advise not having the exact same content on two different URLs--the search engines want to have a single URL for any given bit of content, and may penalize your site for having many different URLs with identical content. A redirect is the best way to fix a link that becomes broken. It's worth reviewing the Top page not found errors report on a regular basis, and if you find a bunch of traffic to a particular URL that's not found, you should create a redirect to the correct location.

Add new comment

The content of this field is kept private and will not be shown publicly.

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <blockquote cite> <cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h1> <h2 id> <h3 id> <h4 id> <h5 id> <p> <br> <img src alt height width>
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.