Is it possible to display the full, absolute URL of the home page in Drupal 7, like www.example.com/The-best-example-possible ?

I'd like to display the full URL of the home page, not just the hostname.

  • are you asking if it's possible to change the location of the home page from example.com/something to example.com/somethingelse? Or do you wan the browser's url bar to display example.com/home when on the home screen?
    – Jance
    Oct 24 '13 at 19:10
  • @Jance Yes, i want that the full URL will be displayed also at the homepage.
    – benosika
    Oct 24 '13 at 19:56
  • Where do you want to display the URL? Can you make your question a bit clearer? Oct 25 '13 at 20:25
  • @benosika Is this the same problem as drupal.stackexchange.com/questions/85838/… ?
    – mpdonadio
    Oct 25 '13 at 21:02

In Drupal 7, The front page is normally set via system_site_information_settings(). It is an unaliased URL, so it is best to use the API. I would do it as:

$home = url(variable_get('site_frontpage', 'node'), array('absolute' => TRUE));

In Drupal 8, there is a special route <front> that you can use with the Url() object

use \Drupal\Core\Url;

$home = Url::fromRoute('<front>')->setAbsolute()->toString();

However, in most circumstances you don't need to explicitly render out Url() objects as strings; you can just use the object itself.

  • Mine's not wrong, but this is much better.
    – jonpeck
    Oct 24 '13 at 20:34
  • Sorry guys, I'm confused. i don't understand what answer is preferable. what file should i go and what exactly do you think i should change there, please help me understand you. Thanks again, very much indeed !
    – benosika
    Oct 24 '13 at 23:40
  • If I understand correctly the answers given here has to do with View-based Front-pages. that's not my issue. I ask only about a Node-based Front-Page.
    – benosika
    Oct 25 '13 at 20:09
  • @benosika Both of these will work with any page set to be the front, not just views pages (I tested with a plain node page).
    – mpdonadio
    Oct 25 '13 at 21:01
  • @mpdonadio how would you do this in d8?
    – awm
    Feb 13 '19 at 17:52
global $conf, $base_url;
echo $base_url . '/' . variable_get('site_frontpage', 'node');

For details, see https://api.drupal.org/api/drupal/developer!globals.php/global/base_url/7 and https://api.drupal.org/api/drupal/includes!path.inc/function/drupal_is_front_page/7

  • Sorry, could you elaborate with some words here? should I first make the changes at the first file and only than the other? I couldn't find the files in my D7 directory, not with search even, could you give directions? Thanks.
    – benosika
    Oct 25 '13 at 12:46
  • 1
    Both of these techniques can be used either in a block, form, even the template. They're not files, this is PHP code. To learn how to make adjustments to the theme, see drupal.org/documentation/theme
    – jonpeck
    Oct 25 '13 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.