After url_alter is enabled, two hooks are implemented: hook_url_inbound_alter and hook_url_outbound_alter. they are used to rewrite the URL and must be implemented by the third-party URL rewriting module. Drupal
The following is an example:
The code is as follows:
/*
* Convert the pseudo address to the original address (url_alter)
*/
Function example_url_inbound_alter (& $ path, $ original_path, $ path_language)
{
If (preg_match ('| ^ article (/. *) |', $ path, $ matches )){
$ Path = 'node'. $ matches [1];
}
}
/*
* Convert the original address to 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 hook_url_inbound_alter is implemented, I do not know why the implementation function cannot be called. it may be because the HOOK is loaded too early and the module is not fully loaded. So my approach is to write it in the URL rewriting module, such as subpath_alias