hook_url_outbound_alter() not working I'm trying to rewrite the URL of a node. I have the following test code:

function mymodule_url_outbound_alter(&amp;$path, &amp;$options, $original_path) {

    if ($path == 'testpage') {
        $path = 'test-alias';
        $options['alias'] = $path;
    }
}


Which doesn't seem to do anything when I visit /testpage or /test-alias. It's definitely executing the code inside the if statement. Am I doing something wrong here?

I have previously implemented hook_url_inbound_alter(), which works perfectly and doesn't do anything on this particular page. I also use the Path module.
If you want to create an alias using hook_url_outbound_alter(), you need to implement also hook_url_inbound_alter(), since the former is for links output from Drupal, and the latter is for links received from Drupal. The former changes the path with its alias, while the latter changes the alias with the equivalent path.

Keep in mind that: 


If you are not doing conditional replacements, then it is probably less performance-heavy to use the normal Drupal path aliases
Between the arguments taken from hook_url_outbound_alter(), $path is the path as already changed by the previously executed module, while $original_path is the path before being changed from any module


Also, $options['alias'] is really a boolean, not a string, which tells url() whenever the path being passed to the function is already a path alias. In the case it is, drupal_get_path_alias() will not be called.