Drupal : Get path and verify if it’s an alias

This is how I get the current path and/or alias in Drupal:
After this code has been executed:
$path will hold the internal drupal path
$alias will hold that path alias if the path in the url is actually an alias, otherwise FALSE;

$path_from_url = isset($_GET['q']) ? $_GET['q'] : '';
$path = drupal_get_normal_path($path_from_url);
if($path === $path_from_url) 
  $alias = FALSE;
else 
  $alias = $path_from_url;

Leave a Reply

Your email address will not be published. Required fields are marked *