custom_url_rewrite($op, $result, $path)
docs-5/hooks/core.php, line 1571
custom_url_rewrite is not a hook. It is a function you can add to settings.php to manage aliases with some code.
$op Can be 'alias' or 'source'. For 'alias', an alias need to be returned. For 'source', return the Drupal path based on the alias passed in. 'source' is first called before modules are loaded and the menu system is initialized and $_GET['q'] subsequently will be the value of what's returned from this function call.
$result For op 'alias', this is the alias of the path from the database. For op 'source', this is the Drupal path based on the database. If there is no match in the database it'll be the same as $path for both ops.
$path The path to be sourced/aliased.
The changed path. Even if it's not changed, it must be returned.
| Name | Description |
|---|---|
| Hooks | Allow modules to interact with the Drupal core. |
<?php
function custom_url_rewrite($op, $result, $path) {
global $user;
if ($op == 'alias') {
// Overwrite a menu path already defined, with this code, if the user
// goes to 'tracker', the page 'views/tracker' will be displayed instead
// without any redirection. To achieve this, only the op source act is a
// must, this is optional.
if ($path == 'views/tracker') {
return 'tracker';
}
// Change all 'node' to 'article'.
if (preg_match('|^node/(.*)|', $path, $matches)) {
return 'article'. $matches[1];
}
// Create a path called 'e' which lands the user on her edit page.
if ($path == 'user/'. $user->uid .'/edit') {
return 'e';
}
}
if ($op == 'source') {
if ($path == 'tracker') {
// Change 'tracker' to 'views/tracker' when a request lands.
return 'views/tracker';
}
// Change all 'node' to 'article'.
if (preg_match('|^article(/.*)|', $path, $matches)) {
return 'node'. $matches[1];
}
// Create a path called 'e' which lands the user on her edit page.
if ($path == 'e') {
return 'user/'. $user->uid .'/edit';
}
}
// Do not forget to return $result!
return $result;
}
?>