I’ve just stumbled across a very useful internal function in Drupal that I thought I’d share here.
If you have a node that you know the node ID for, but you don’t know what the full clean url is (or how to generate it), then there is a handy function you should know about called drupal_lookup_path() that will get the full clean (pathauto) path for you. For example, a typical Drupal relative path such as:
Is easy to generate if you know the node ID, but if you pass it through the drupal_lookup_path function like so:
Then you will get the full clean path of the node based on the rules set out in the pathauto module. For example:
This is very important for SEO. If the exact same content/page can exist on two different urls on your site, then you will run into problems with duplicate content and will have to start using things like the canonical link element to fix a problem that shouldn’t have been created in the first place.