The Translation redirect module, part of the Internationalization (i18n) package, improves search engine optimization (SEO) for multilingual websites. By default, multilingual pages can be accessed via different paths by changing the path prefix or domain. Search engines tend to penalize displaying the same content at more than one URL, so it's important to redirect to a single instance of the page.

The Translation redirect module redirects anonymous users (including web crawlers) to the translation of the page in the requested language, if it exists, using a 301 redirect code. For example, if the request is for /de/node/23 and node/23 corresponds to an English page, the user will be redirected to the German translation of the English node if it exists. If the translation does not exist, then the source node content is displayed.

Note that, by design, translation redirection does not work for the homepage or for authenticated users.

Design and Dependencies

The Translation redirect module requires the implementation of hook_i18n_translate_path by another module for the redirect page to be determined. Currently, the Multilingual content, Path translation, and Taxonomy translation modules implement this hook. The Menu translation module has a "todo" to implement this hook as well.

Usage

For node pages, enable the Multilingual content and the Translation redirect modules and the redirection will happen automatically for node pages. No configuration is necessary.

For non-node pages, the redirection hook must be implemented by the relevant module. For example, for taxonomy pages, you should enable the Taxonomy translation module because the module provides the necessary hook code. If you are using the Path translation module to create translation sets for non-node pages, then it implements the hook code for determining the redirection page.

Comments

Wolfgang Reszel’s picture

What to do, if I want the opposite redirect?

/de/node/23 should redirect to /en/node/23

Wolfgang Reszel’s picture

This code helps me, but I don't know if it's a good solution. (I called the custom module i18n_context_redirect).

/**
 * Implements hook_init()
 */
function i18n_context_redirect_init() {
  global $language,$drupal_path;
  $path = current_path(); // current path
  $destination = drupal_get_destination(); // destination query string
  unset($_GET['destination']); // remove the destination query from $_GET so drupal_goto works as expected
  $context_language = i18n_language_context(); // get the language of the context (node)
  
  // Is current language different from the language of the context (node)?
  if ($language->language != $context_language->language) {
    $language = $context_language; // Change language
    drupal_goto($path, array('language' => $context_language, 'query' => $destination), 301); // Goto same path with different language
  }
}


Andy Inman’s picture

/de/node/23 should redirect to /en/node/23

You can do that with MultiLink Redirect with suitable configuration. With default configuration it would redirect to the language specified by browser-settings, if available, and redirect to German (in your example) if no browser-language preference is available.