How to get the full url of a Drupal page?

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

I am NOT looking for a path to a topic, or a base url, or Drupal get_destination. I am looking for a function or variable that will give me the following:

http://example.com/node/number

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

+45
php drupal content-management-system
Mar 31 '09 at 23:04
source share
9 answers

drupal_get_destination () contains some internal code that points to the right place to get the current internal path. To translate this path into an absolute URL, the url () function should do the trick. If the "absolute" option is passed to it, it will generate the full URL, not just the internal path. It will also replace any path aliases for the current path.

 $path = isset($_GET['q']) ? $_GET['q'] : '<front>'; $link = url($path, array('absolute' => TRUE)); 
+53
Apr 01 '09 at 0:30
source share

Here is what I found useful.

 global $base_root; $base_root . request_uri(); 

Returns query strings and what is used in the kernel: page_set_cache ()

+37
Aug 03 '09 at 4:32
source share

You can also do it like this:

 $current_url = 'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 

This is a little faster.

+19
Jan 27 '10 at 14:15
source share

Try the following:

 url($_GET['q'], array('absolute' => true)); 
+14
Apr 3 '09 at 13:56
source share

This method is an old method, in drupal 7 we can get it very simply

  current_path() 

and another function with a small difference

 request_path() 
+12
May 22 '12 at 5:16
source share

I use tokens pretty clean. It is integrated into the core in Drupal 7.

 <?php print token_replace('[current-page:url]'); ?> 
+4
Sep 20
source share

Below is more Drupal-ish:

 url(current_path(), array('absolute' => true)); 
+3
Mar 03 '15 at
source share

For Drupal 8, you can do this:

 $url = 'YOUR_URL'; $url = \Drupal\Core\Url::fromUserInput('/' . $url, array('absolute' => 'true'))->toString(); 
0
Feb 22 '17 at 12:12
source share

Perhaps what you want is just the old predefined variables.

Consider the attempt

 $_SERVER['REQUEST_URI''] 

Or read here .

-one
Mar 31 '09 at 23:10
source share



All Articles