How To Set Node Path/Alias Programatically
The canonical URL for a node is http://example.com/node/&lt;nid&gt;; if you want to set a path alias, you need to set it with path_set_alias('node/' . $node-&gt;nid, $alias).