In hook_node_insert drupal_goto with alias name not working In hook_node_insert() i have used drupal_goto(), to go to the newly created node with alias name of it, but id doesn't work. 

I have already created url alias with patterns for that content type.

$alias = drupal_get_path_alias('node/'.$node-&gt;nid);
drupal_goto($alias);


If i give drupal_goto() with nid it works.

drupal_goto('node/'.$node-&gt;nid);


What is the issue with respect to alias name not working or how to get alias of newly created node and get it redirected to view page of it with alias name as url.

Any ideas or suggestions? Thanks in advance. 

[Updated code]

This is the code which i am trying

function hook_node_insert($node)
{
    if($node-&gt;type == 'product')
    {

        $_SESSION['product_node_nid'] = $node-&gt;nid;
        $banner = $_SESSION['banner'];
        $theme = $_SESSION['theme'];
        $params = array();
        $params['node'] = $node;
        $site_email = variable_get('site_mail', '');                
        if(($banner || $theme) || ($banner &amp;&amp; $theme)) {
            drupal_goto('payment-approval');
        }
        else {
            //$alias = drupal_get_path_alias('node/'.$node-&gt;nid);
            module_load_include('inc', 'pathauto'); // include the inc file for Pathauto module
            pathauto_create_alias('node', 'insert', 'node/'.$node-&gt;nid, array('node' =&gt; $node), $node-&gt;type, $language-&gt;language); // Language is optional
            $alias = drupal_get_path_alias('node/'.$node-&gt;nid);
            //$alias = drupal_get_path_alias('node/'.$node-&gt;nid); print_r($alias); exit();
            drupal_goto($alias);
        }
    }
}
I checked the drupal_goto and found out that you must provide the path for parameter. You can't use alias for drupal_goto. So i think you can solve your problem like that:


While you create node. You will also create the alias for that node. The reference for create the alias for node here. In your code just normally redirect like that

drupal_goto('node/'.$node-&gt;nid);

After that you will install Global redirect module. This module will have responsibility to redirect your node/nid to your node's alias


[Updated]

Can you try to generate the alias by using the Pathauto. So can you put these code in hook_insert()

function yourmodule_node_insert($node){
  module_load_include('inc', 'pathauto');
  pathauto_cleanstring($node-&gt;title);
  $node-&gt;path = array('pathauto' =&gt; TRUE );
  drupal_goto('node/'.$node-&gt;nid);
}