i18n language prefix + SEO

walden - June 4, 2007 - 16:46

I am looking to create a Spanish translation for ~300 page drupal site. I'd like to use the i18n module, but don't want to change the urls of my English pages for SEO reasons. My urls are currently domain.com/products/overview and I don't want to have the domain.com/en/products/overview alias as part of the site. [i18n seems to automatically assign the en/ prefix to everything]

For the translated site I would like to either use domain.es/products/overview (preffered) or domain.com/es/products/overview

Does anyone know how to kill the en/ for the English version or seen it done elsewhere?

Thanks!

=-=

VeryMisunderstood - June 4, 2007 - 17:17

may have to use the path.module and create url alias to by pass the/en/ or the pathauto.module

I faced a similar issue

zsanmartin - June 4, 2007 - 18:00

I faced a similar issue recently when I wanted to use the code "br" in a URL instead of "pt-br".

I have patched a few lines in i18n.module that allowed me to create a custom language prefix for URLs only, while using the regular language prefix everywhere else, such as in the HTML headers. I don't know if it's going to work with you, since you want a blank custom prefix, which may cause a few problems. You should try, anyway.

The patch for i18n.module's i18n_get_lang_prefix function is:

<?php
//Patch here:
function i18n_get_lang_prefix(&$path, $trim = FALSE) {
 
$exploded_path = explode('/', $path);
 
$path_tail = array_shift($exploded_path);
  if (
function_exists('custom_language_url_prefix')) {
   
$maybelang = custom_language_url_prefix('dealias', $path_tail);
  } else {
   
$maybelang = $path_tail;
  }
 
$languages = i18n_languages();
  if (
array_key_exists($maybelang, $languages)){
    if (
$trim) {
     
$path = trim(substr($path, strlen($path_tail)),'/');
    }
    return
$maybelang;
  }
}
?>

and for i18n.module's custom_url_rewrite function:

<?php
//patch here:
if(!function_exists('custom_url_rewrite')) {
  function
custom_url_rewrite($type, $path, $original) {
   
$return = i18n_url_rewrite($type, $path, $original);

    if (
function_exists('custom_language_url_prefix')) {
     
$return = custom_language_url_prefix('alias', $return);
    }

    return
$return;
  }
}
?>

Now, all you have to do is to create a function in your settings.php called custom_language_url_prefix. The function below changes "pt-br" into "br" in urls:

<?php
//$op may have two values: "alias" and "dealias"
function custom_language_url_prefix($op, $language) {
  if (
$op == 'dealias') {
    if (
$language == 'br') {
      return
'pt-br';
    } else {
      return
$language;
    }
  }

  if (
$op == 'alias') {
    if (
preg_match('|^pt-br(/.*)|', $language, $matches)) {
      return
'br' . $matches[1];
    } else {
      return
$language;
    }
  }
}
?>

To use it in your website, replace "pt-br" with "en" and "br" with blank and tell me later if it works with you.

Regards,

José San Martin
http://www.gare7.org/

I'll give it a shot, thanks

walden - June 4, 2007 - 21:17

I'll give it a shot, thanks

 
 

Drupal is a registered trademark of Dries Buytaert.