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;

1
2
3
4
5
6
$path_from_url = isset($_GET['q']) ? $_GET['q'] : '<front>';
$path = drupal_get_normal_path($path_from_url);
if($path === $path_from_url) 
  $alias = FALSE;
else 
  $alias = $path_from_url;

Related links

Leave a Reply

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

*

* Copy this password:

* Type or paste password here:

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">