当前位置: 首页 > 新闻动态 > 软件编程

drupal 代码实现URL重写

作者:用户投稿 浏览: 发布日期:2026-01-16
[导读]:开启了url_alter后,将实现两个HOOK,hook_url_inbound_alter与hook_url_outbound_alter,作用是重写URL,第三方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
免责声明:转载请注明出处:http://m.hclxt.cn/news/845804.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!