How to set a custom URL for a node without pathauto? I have a content type that requires me to assemble a URL from several sources - the node title, a taxonomy value, and some fields of a product that are referenced from a product display that this content type references.  So:

mynode type
  - title
  - taxonomy value
  - entity ref -> product display -> product field  

The entity ref can have one or more products, so there is some logic I need to crunch to assemble the right URL.  I didn't have luck doing this through pathauto, so it looks like I need to handle this on hook_node_presave(), which does set my alias, but I get a 404 on that alias, so it seems I'm missing a step.

My code is:

mymodule_node_presave($node) {
    if (empty($node-&gt;path['alias'])) {
        $node-&gt;path['alias'] = _some_fx_that_figures_out_url();
        $node-&gt;path['pid'] = 0;  
        $node-&gt;path['language'] = LANGUAGE_NONE;  
    }
}


I guess I'm missing something?
This seems to be a duplicate of this issue

Try using hook_node_insert($node) for new content and/or hook_node_update($node) for existing content:

function mymodule_node_insert($node) {
  if ($node-&gt;type == 'mytype') {
    $node-&gt;path['alias'] = _some_awesome_pattern_maker($node);
  }
}

function mymodule_node_update($node) {
  if ($node-&gt;type == 'mytype') {
    $node-&gt;path['alias'] = _some_awesome_pattern_maker($node);
  }
}

_some_awesome_pattern_maker($node) {
  // massage node and return string
}