You can use url() to generate a base url to any route in Drupal. You can supply the <front> route which, in effect, will be your base URL.
Answer: Use the window. location. href Property location. href property to get the entire URL of the current page which includes host name, query string, fragment identifier, etc.
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));
This is what I found to be useful
global $base_root;
$base_root . request_uri();
Returns query strings and it's what's used in core: page_set_cache()
You can also do it this way:
$current_url = 'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
It's a bit faster.
Try the following:
url($_GET['q'], array('absolute' => true));
This method all is old method, in drupal 7 we can get it very simple
current_path()
and another function with tiny difference
request_path()
I find using tokens pretty clean. It is integrated into core in Drupal 7.
<?php print token_replace('[current-page:url]'); ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With