Drupal Get path alias from current url without installation folder arguments

I would like to get the current page path alias without installation folder arguments. I use:

drupal_get_path_alias(request_uri()) 

But this returns the installation / independently / actual / path , and I want to get the actual / path only no matter what installation / what is.

Thanks in advance:)

+4
source share
7 answers

Found. In fact, it was a combination of both sentences:

 $current_path = drupal_get_path_alias($_GET["q"]); 

Thanks, though.


Update: previous solution not always working

Someone suggested using an alternative method:

 str_replace(base_path(), '', drupal_get_path_alias(request_uri(), 1)); 

But is there a way to do the same without using the slightly expensive str_replace?

thanks

+9
source

Are you on your way to node?

http://api.drupal.org/api/function/drupal_get_path_alias/6

 if ($node || (arg(0) == 'node' && arg(2) != 'edit')) { $system_path = 'node/'.arg(1); $current_path = drupal_get_path_alias($system_path); } 

This code will light up on the node pages and tell you the page alias.

For more information, you can unload $ _GET and see the string value of q.

+2
source

Perhaps you can use base_path () and str_replace as follows:

 str_replace (base_path(), '', drupal_get_path_alias(request_uri()), 1); 

The base_directory is stored in the database.

+1
source
 $current_page_url = drupal_get_path_alias( implode( '/', arg() ) ); 

also works

+1
source

Have you tried $_GET['q'] ?

0
source

I try to completely confuse the full URL to avoid any problems that arise when base_path () is not just "/".

 $url = (($_SERVER['HTTPS'])?"https://":"http://") . $_SERVER['HTTP_HOST'] . url($_GET['q']); 

or even simpler:

 $url = url($_GET['q'], array('absolute'=>true)); 
0
source

The fastest solution.

substr(drupal_get_path_alias(request_uri(), 1), strlen(base_path()));

To pass it to an argument

$arg = explode('/', substr(drupal_get_path_alias(request_uri(), 1), strlen(base_path())));

0
source

Source: https://habr.com/ru/post/1312213/


All Articles