6.x core.php custom_url_rewrite_inbound(&$result, $path, $path_language)

custom_url_rewrite_inbound is not a hook, it's a function you can add to settings.php to alter incoming requests so they map to a Drupal path. This function is called before modules are loaded and the menu system is initialized and it changes $_GET['q'].

This function should change the value of $result by reference.


$result: The Drupal path based on the database. If there is no match in the database it'll be the same as $path.

$path: The path to be rewritten.

$path_language: An optional language code to rewrite the path into.

Related topics

1 call to custom_url_rewrite_inbound()
drupal_get_normal_path in includes/path.inc
Given a path alias, return the internal path it represents.


developer/hooks/core.php, line 2782
These are the hooks that are invoked by the Drupal core.


function custom_url_rewrite_inbound(&$result, $path, $path_language) {
  global $user;

  // Change all article/x requests to node/x
  if (preg_match('|^article(/.*)|', $path, $matches)) {
    $result = 'node' . $matches[1];

  // Redirect a path called 'e' to the user's profile edit page.
  if ($path == 'e') {
    $result = 'user/' . $user->uid . '/edit';


dgtlmoon’s picture

Remember, if you're rewriting the complete path to a new path that may exist in url_alias, you should call drupal_lookup on your final return because this function call occurs AFTER Drupal calls its drupal_lookup_path.

or you will get 404's on paths that are aliased etc.

function custom_url_rewrite_inbound(&$result, $in_path, $path_language) {

  $result = preg_replace("/(somethingfiddly)./", "", $in_path);

  if ($src = drupal_lookup_path('source', $in_path, $path_language)) {
    $result = $src;
DRippstein’s picture

This is replaced in Drupal 7 with hook_url_inbound_alter

scottatdrake’s picture

There is a Drupal 6 contrib module that provides these hooks without adding them to settigns.php: https://drupal.org/project/url_alter