我想重定向使用错误网址别名的网址。
示例,在我的网站中我有: 英语 - > / price / high-school - >节点/ 112 西班牙语 - > (/ es)/ precios / high-school - >节点/ 115
当某人或搜索引擎到达/ es / price / high-school时,将返回404。我想要的是将/ es / prices / high-school重定向到node / 115。
我想以一般形式,编写模块或使用现有模块,如果可能的话。
感谢。
答案 0 :(得分:1)
我已经明白了。
在preprocess hook中我需要检查页面,去除前缀并从原始id中获取节点id。
见下面的代码:
if(current_path()=="search404")
{
$url = request_path();
if (startsWith($url,'es/') ||
startsWith($url,'de/') ||
startsWith($url,'it/') ||
startsWith($url,'fr/') )
{
$originalPath = substr($url,3,strlen($url)-3);
$path = drupal_lookup_path("source", $originalPath,"en");
if (isset($path))
{
$node = menu_get_object("node", 1, $path);
if (isset($node))
{
$prefix = substr($url,0,2);
$translated_paths = translation_path_get_translations('node/' . $node->nid);
if (isset($translated_paths) && array_key_exists ($prefix,$translated_paths))
{
if (isset($_GET['destination'])) {
unset($_GET['destination']);
}
$new_path = $translated_paths[$prefix];
drupal_goto($new_path, array(),301);
}
}
}
}
}
答案 1 :(得分:0)
为语言版本添加不同的url别名不是一个解决方案吗?我的意思是:
node / 112 - > /价格/高中 节点/ 115 - > / ES / precios / ESCUELA-secundaria
i18n模块处理基于语言的路径并重定向。