Drupal 7: how to get absolute path url or path alias url of a node

In Drupal 7 we can access to a node through its absolute path url or through its path alias. In some case it is really useful get these urls and as usually in drupal we can do this in a lot of ways, here there are some examples.

Code to get absolute url:

global $base_url;
$nodeurl = $base_url . '/' . current_path();
$nodeurl = url('node/'. $node->nid);

Code to get path alias url:

$nodeurl = url('node/' . $node->nid, array('absolute' => TRUE));
$path = isset($_GET['q']) ? $_GET['q'] : '<front>';
$nodeurl = url($path, array('absolute' => TRUE));
$nodeurl = $base_dir .  drupal_get_path_alias($path);
global $base_url;
$url = $base_url . drupal_get_path_alias(request_uri());

 

Tags: