J. URL Aliases

"URL" is an abbreviation of "Uniform Resource Locater." It is a fancy way of saying "my page's address (or name) on the web." It is the "name" by which a browser identifies a page to display. We've all seen advertisements that say "Check us out at abcxyz.com." Well, abcxyz.com is a URL for the home page of their web site (well, sort of - there is an implied add-on to that, such as index.html).

By default, Drupal calls your content "nodes" and identifies them by their position in your database. So your page on "The History of the Macadamia Nut - Part 1" might be known as "node/167." That's all fine and well for Drupal, because it understands that. But your visitor really doesn't care where the page is in the database; all they want to do is find the page again, or know what the entry in their bookmarks list is.

So Drupal has a feature called "URL Alias" that allows you to provide a more understandable name to the content. As far as browsers, servers, and search engines go, it is totally unnecessary. But for humans, it is nearly mandatory. This is why I tell people to always turn on the Path core module, which supports URL Aliasing. (I will mention another module shortly, called Pathauto.)

So, just before you submit that exhaustive treatise on macadamia history, and if you have the Path module enabled (I told you that you'd want it), then you'll see a section on the edit page that says "URL path settings." So let's say you want your visitors to see it as http://www.mysite.com/MacadamiaHistory.htm. In the URL field, you enter MacadamiaHistory.htm.

Now, some people will argue that putting that ".htm" on the end is not necessary. That's absolutely true. But then it's not necessary to do any of this. My opinion is that if you want your visitors to see a "normal" name, it should look like a normal WEB name. Web pages have some kind of type, such as ".htm" so we should too. But it's your preference.

Oops, forgot to do this before you submitted the page? Not to worry - Drupal to the rescue!

First, visit the page you created. In your browser's address field, you'll see its URL. On the end it will probably say "node/xxx" where xxx is some number. Write down that number. Now go to Administer>>Site building>>URL Aliases. There's an "Add Alias" tab at the top. In the top box (sorry, they seem to have dropped a label in 5.1), enter "node/xxx" from above. In the second box, enter "MacadamiaHistory.htm".

Now go back and visit that page and look at your browser's URL field.

If your site is going to have lots of content, particularly user-submitted content, you might want to looks at the PathAuto module. Not only will this module automatically generate URL aliases for new content (according to rules you can set up), but can even go back and change aliases in bulk.

 

Path Auto and mod_rewrite

WebKenny - March 2, 2008 - 15:36

This is a great resource. Just a quick question to anyone who might know. How does Path differ from the CleanURLs function of Drupal? Do you need mod_rewrite enabled to work with Path? Some of us on shared hosts unfortunately cannot access mod_rewrite and if this is another possibility for us, that would be fantastic.

EDIT: I managed to figure out the difference for others concerned. While usually your pages will appear with node/xxx, this Path module allows for the pages to appear as /?q=alias by default - If you did, indeed, have mod_rewrite and CleanURLs enabled then the same page would appear as simply /alias in the address bar.

Kenny S.
Developer by day, entertainer by night.
webkenny.com

 
 

Drupal is a registered trademark of Dries Buytaert.