drupal 代码实现URL重写

网络编程 发布日期:2024/10/13 浏览次数:1

正在浏览:drupal 代码实现URL重写
以下是实现例子:
复制代码 代码如下:
/*
* 伪地址转原地址 (url_alter)
*/
function example_url_inbound_alter(&$path, $original_path, $path_language)
{
if (preg_match('|^article(/.*)|', $path, $matches)) {
$path = 'node'. $matches[1];
}
}
/*
* 原地址转伪地址 (url_alter)
*/
function example_url_outbound_alter(&$path, &$options, $original_path)
{
if (preg_match('|^node(/.*)|', $path, $matches)) {
$path = 'article' . $matches[1];
}
}

PS: 实现hook_url_inbound_alter时不知为何会调不出实现函数,可能因为HOOK过早加载,没有把module加载完全。所以我的做法是写在URL重写模块中,例如subpath_alias