Drupal Quick Tip: Auto “node/nid” Paths from Alias in Menus

Dev

Drupal Quick Tip: Auto “node/nid” Paths from Alias in Menus

“In learning you will teach, and in teaching you will learn.”

Words spoken by (or, at least, attributed to) the great Phil Collins (side story: my first conversation with anyone at InterWorks was with Aaron Confer discussing Genesis and Phil Collins). During my last training at OSU, I definitely learned something new.

For people brand new to Drupal, I typically start with the basics – creating and editing content. Doing this covers about 70% of what most non-developers will do with their Drupal sites. Next up is creating menus and menu items. When creating menu items, I teach that one should use “node/nid” in the alias. This is typically so that the menu item keeps the menu link even if the alias changes, which can happen if the title of the node changes (say, for an updated news item).

If you don’t know what an alias is, an alias is the part directly after your domain. For example, in https://www.interworks.com/company/our-team, “company/our-team” is the alias. And Drupal has a couple of really good modules that handle path aliasing.

Pathauto is one that I like a lot. Pathauto allows admins to set a pattern for each content type that will automatically assign an alias as each new node is created. For example, in a News content type, the pattern can be set to use the published date and title to form the alias. So instead of being example.com/node/17 or example.com/content/[title], it could be /news/[node:created:custom:Y]/[node:created:custom:m]/[node:created:custom:d]/[title], which would output example.com/news/2013/04/19/node-title.

Redirect is kind of like Drupal’s built-in aliasing on steroids. It offers different types of redirects (300 through 307. More about redirection codes here: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection), helps fix 404 pages, and even a few extra settings like expiring redirects.

Global Redirect runs in the background and helps to optimize the alias process. It does an auto 301 if the current URL is not being used, checks for and removes the trailing slash, checks and redirects to the homepage if needed, and several other things. The module creators note that Global Redirect not only gives you clean URLs but can help protect your site from being sandboxed, since Drupal doesn’t remove the original (node/1234) path and, with two paths pointing to the same content can be seen as a bad practice to search engines.

So, from my training, I learned that, even if one adds the clean alias to the menu item, Drupal will automatically convert it to the “node/nid” format. So instead of having to teach users (especially beginners) how to find the node ID, you can just put in the alias and you’re good to go.

tl;dr: Use the clean alias when creating menu items. It’s easier to remember and Drupal converts it to “node/nid” anyway.

Happy aliasing.

Setting the Path Alias:

Screenshot of setting the path alias

 

Creating the menu item path using the clean alias:

Screenshot of setting the path using the alias

 

Confirmation of Drupal converting the menu item path from a clean alias to the node/nid: 

Screenshot confirming Drupal converting the menu path alias from a clean alias to the node/nid

More About the Author

Chris Armstrong

Multimedia Manager
Drupal Quick Tip: Auto “node/nid” Paths from Alias in Menus “In learning you will teach, and in teaching you will learn.” Words spoken by (or, at least, attributed to) the great Phil ...
Quick Tutorial on Overriding Drupal Views using Templates Scott and I were recently invited to Oklahoma State University to provide Drupal training for their web admins. Drupal has been on the ...

See more from this author →

Subscribe to our newsletter

  • I understand that InterWorks will use the data provided for the purpose of communication and the administration my request. InterWorks will never disclose or sell any personal data except where required to do so by law. Finally, I understand that future communications related topics and events may be sent from InterWorks, but I can opt-out at any time.
  • This field is for validation purposes and should be left unchanged.

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072