Drupal - Convert link from node/nid to Pathauto url?

I would, as Splat mentioned, check out the Global Redirect module, which will help out with google not seeing node/FOO and pretty/path pointing to identical content. If, however you are wanting to make sure that when engines scan your page content and pretty/path shows up inside the HTML, you can either continue to hardcode the paths, or create a function that returns the aliased path based on the nid.

function make_my_path($nid) {
  $pretty_path=drupal_get_path_alias('node/' . $nid);
  return $pretty_path;
}

Then use that (or drupal_get_path_alias() directly) in your templates or preprocess functions, or just use l(). If it is passed 'node/FOO' as the path, it will return the aliased path if one is set. (Unless you explicitly tell it not to; see url().)

So, for example, print l('Hello World','node/23'); should return <a href="/pretty/path/to/node/23">Hello World</a>.


If you're using CKEditor, you should use the CKEditor Link module. It allows searching content by title to insert, and in Drupal it saves the link as /node/[ID]. Then a text filter (which you'll need to enable for each text format it's being used on) replaces that URL with the current path alias in the rendered page.


I think you're looking for the Global Redirect module. This will make sure whenever you link to node/x that anyone following the link is redirected to the clean URL for that node.