By hari, 13 July, 2023 <?php // To get the base url $host = \Drupal::request()->getSchemeAndHttpHost(); //https://www.local.com $current_url = Url::fromRoute('<current>'); $path = $current_url->toString(); //Examples for the page /en/user/login: $current_url->toString(); // /en/user/login $current_url->getInternalPath(); // user/login $path = $current_url->getRouteName(); // <current> //Drupal syntax. $path = \Drupal::request()->attributes->get('_system_path'); // Include a query string $current_uri = \Drupal::request()->getRequestUri(); // For the current raw path (the un-aliased Drupal path): $current_path = \Drupal::service('path.current')->getPath(); $result = \Drupal::service('path_alias.manager')->getAliasByPath($current_path); //Get the url of the request for displayed on the browser. $page = \Drupal::request()->getRequestUri(); ?> Tags Drupal