The drop is always movingYou know that saying about standing on the shoulders of giants? Drupal is standing on a huge pile of midgetsAll content management systems suck, Drupal just happens to suck less.Popular open source software is more secure than unpopular open source software, because insecure software becomes unpopular fast. [That doesn't happen for proprietary software.]Drupal makes sandwiches happen.There is a module for that

URI, path, aliases, oh my!

Submitted by nk on Sun, 2011-10-30 22:16

Say you have http://example.com/drupal/documentation?page=1. Let's presume documentation is an alias for node/26419

Then after a full bootstrap

$GLOBALS['base_url'] http://example.com/drupal
base_path() /drupal/
request_uri() /drupal/documentation?page=1
request_path() documentation
current_path() node/26419

Note that base_path() is a one line wrapper for returning the global $base_path and similarly current_path() just returns $_GET['q']. Unlike in previous versions of Drupal, the 'q' variable is not loaded by .htaccess but computed during bootstrap and so the old method of reading $_REQUEST['q'] for the original path does not work in Drupal 7, use request_path() instead.

Pay attention to slashes on the bases: base_url never has a slash at the end while base_path always has one.

Finally note that before the full bootstrap (hook_boot, cache backends and other early plugins) the current_path() function doesn't exist and $_GET['q'] is still 'documentation'. The rest is set up extremely early so those can be relied upon.

Commenting on this Story is closed.

Submitted by Anonymous on Mon, 2011-10-31 08:00.

This looks like a Drupal certification question

Submitted by Anonymous on Mon, 2011-10-31 13:37.

This is helpful; thanks! How does arg() factor in here?

Submitted by nk on Mon, 2011-10-31 17:41.

it's explode('/', $_GET['q']) and current_path is return $_GET['q'].