Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
drupal重定向语言url别名_Url_Redirect_Drupal_Alias_Multilingual - Fatal编程技术网

drupal重定向语言url别名

drupal重定向语言url别名,url,redirect,drupal,alias,multilingual,Url,Redirect,Drupal,Alias,Multilingual,我想重定向使用错误url别名的url 例如,在我的网站中,我有: 英语->/prices/high-school->node/112 西班牙语->(/es)/precios/high-school->node/115 当某人或搜索引擎到达/es/prices/high-school时,返回404。我想将/es/prices/high-school重定向到node/115 我想以一种通用的形式来做这件事,写一个模块或者使用一个现有的模块(如果可能的话) 谢谢。为语言版本添加不同的url别名不是一个

我想重定向使用错误url别名的url

例如,在我的网站中,我有: 英语->/prices/high-school->node/112 西班牙语->(/es)/precios/high-school->node/115

当某人或搜索引擎到达/es/prices/high-school时,返回404。我想将/es/prices/high-school重定向到node/115

我想以一种通用的形式来做这件事,写一个模块或者使用一个现有的模块(如果可能的话)


谢谢。

为语言版本添加不同的url别名不是一个解决方案吗?我的意思是:

node/112->/prices/high-school node/115->/es/precios/escuela secundaria


i18n模块也处理基于语言的路径和重定向。

我已经解决了这个问题

在预处理钩子中,我需要检查页面,去掉前缀并从原始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);
                }

            }
        }
    }
}

谢谢你的回答。这可能是一个很好的解决方案。然而,我自己已经找到了解决办法。稍后我会发布解决方案,因为系统还不允许我回答自己的问题。