drupal code implements URL rewrite
- 2020-05-05 11:02:54
- OfStack
Here is an example of the implementation:
PS: when implementing hook_url_inbound_alter, I don't know why I can't call the implementation function. Maybe because HOOK loaded too early, module was not fully loaded. So what I did was write it in the URL rewrite module, such as subpath_alias
/*
* Pseudo address to original address (url_alter)
*/
function example_url_inbound_alter(&$path, $original_path, $path_language)
{
if (preg_match('|^article(/.*)|', $path, $matches)) {
$path = 'node'. $matches[1];
}
}
/*
* Turn the original address into a pseudo-address (url_alter)
*/
function example_url_outbound_alter(&$path, &$options, $original_path)
{
if (preg_match('|^node(/.*)|', $path, $matches)) {
$path = 'article' . $matches[1];
}
}
PS: when implementing hook_url_inbound_alter, I don't know why I can't call the implementation function. Maybe because HOOK loaded too early, module was not fully loaded. So what I did was write it in the URL rewrite module, such as subpath_alias