There are a few ways to get the current URL in Drupal 7. First, we can get the $_GET[‘q’] by the current_path() function. But it will ignore the language prefix if you are working on a multilingual site.
Examples of current_path():
- http://example.com/node/306
- returns “node/306”
- http://example.com/drupalfolder/node/306
- returns “node/306” while base_path() returns “/drupalfolder/”
- http://example.com/path/alias
- returns internal path such as “node/306” as opposed to the path alias
- http://example.com/en/path/alias
- returns internal path such as “node/306” as opposed to the path alias and language prefix is ignored
There is also another function called request_path() which may also help you to get the current path with language prefix.
Examples of request_path():
- http://example.com/node/306
- returns “node/306”
- http://example.com/drupalfolder/node/306
- returns “node/306” while base_path() returns “/drupalfolder/”
- http://example.com/path/alias
- returns “path/alias” as opposed to the internal path
- http://example.com/en/path/alias
- returns en/path/alias
- http://example.com/index.php
- returns an empty string (meaning: front page)
- http://example.com/index.php?page=1
- returns an empty string
Another function to get the current URL is request_uri() which returns the $_SERVER[‘REQUEST_URI’] value.
Done =)
Reference:
merciiiiiii !
LikeLike
De rien~ =D
LikeLike
Does it handle the site prefix?
LikeLike
request_path() works for language prefix.
LikeLike