Find URL alias for a node

Use this snippet to find the URL alias for a node by looking it up in the url_alias table by its node ID.

  1. $src = 'node/'.$node->nid;
  2. $path = db_result(db_query("SELECT dst FROM url_alias WHERE src = '%s'",$src));

If you liked this, you'll love my book, Master Drupal Module Development.

"..the must have drupal developers book"


Feeling stuck with Drupal 8 module dev?

Get the free 7 lesson course that will help you get started today without feeling overwhelmed.

  • Create Drupal modules with just a few commands using the Drupal Console
  • Create custom pages
  • Create custom blocks
  • Create admin forms
  • Demystify routers and controllers
  • Bonus material

Find out more


Add new comment