I wonder how to convert a URL path back to it's own node (node/nid). I wish to get the original node ID from a given path. e.g.
path = "news/my-news"
..and trace it back to get it's own original URL, e.g. 65. Please advise. Thanks.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI wonder how to convert a URL path back to it's own node (node/nid). I wish to get the original node ID from a given path. e.g.
path = "news/my-news"
..and trace it back to get it's own original URL, e.g. 65. Please advise. Thanks.
GokulNK has already given the answer to use drupal_get_normal_path()
. If you are working on any path alias that is different than the current path, use that.
If you want to get the non-aliased path of the current page/path, simply use $_GET['q']
.
Drupal path aliases are mod_rewrites but you still can find the internal path from $_GET['q']
.
For node paths or any structured paths and if you want to get the node ID or something, now don't explode('/', $_GET['q'])
:)
Meet arg()
.
Aliased path: content/my-new-page
$_GET['q']: node/69
arg(0) = node
arg(1) = 69
drupal_get_normal_path('content/my-new-page')
(Probably require some db trips unless cached)You can use drupal_get_normal_path function.
Return value
The internal path represented by the alias, or the original alias if no internal path was found.
All the URl path are stored in database so you can configure it in admin/config/search/path whether your are using pathauto or writing your own url alises. Deleting from admin setting may convert a URL path back to it's own node (node/nid).