How to get the full URL of a Drupal page?

2019-01-30 10:29发布

I need to be grabbing the URL of the current page in a Drupal site. It doesn't matter what content type it is - can be any type of node.

I am NOT looking for the path to theme, or the base url, or Drupal's get_destination. I'm looking for a function or variable that will give me the following in full:

http://example.com/node/number

Either with or without (more likely) the http://.

9条回答
Rolldiameter
2楼-- · 2019-01-30 11:24

drupal_get_destination() has some internal code that points at the correct place to getthe current internal path. To translate that path into an absolute URL, the url() function should do the trick. If the 'absolute' option is passed in it will generate the full URL, not just the internal path. It will also swap in any path aliases for the current path as well.

$path = isset($_GET['q']) ? $_GET['q'] : '<front>';
$link = url($path, array('absolute' => TRUE));
查看更多
SAY GOODBYE
3楼-- · 2019-01-30 11:27

The following is more Drupal-ish:

url(current_path(), array('absolute' => true)); 
查看更多
我想做一个坏孩纸
4楼-- · 2019-01-30 11:32

I find using tokens pretty clean. It is integrated into core in Drupal 7.

<?php print token_replace('[current-page:url]'); ?>
查看更多
登录 后发表回答