Hi,

this issue is new - I updated several modules and drupal core just a few days ago and now this issue appears in one of my projects: i18 installed, two languages (German and English), English pages have the prefix "en", German is standard.

I have one rule which redirect users after login with a special role to an node adding form. The redirect action is just a redirection to "node/add/content". Before the updates everything worked fine: German users were redirected to "node/add/content", English users to "en/node/add/content" - but now English users are redirected to "en/en/node/add/content".

Does anyone has an idea what can cause this problem?

Best,
Tobias

Comments

Anders Östberg’s picture

I'm seeing the same problem; I also have a rule that redirects users at login, to different start pages (on the form node/nid) depending on user role. Both languages have prefixes (sv and en) and I get double language prefixes for both languages.

Any fix or workaround for this would be greatly appreciated, it's stopping my web site migration right now.

EDIT: Sorry, I didn't check the version ... I'm on Drupal 7.15 and Rules 7.x-2.2, should I perhaps start a new thread?

tobiberlin’s picture

I simply used .htaccess to redirect as I did not find another solution:

RewriteRule ^en/en(.*)$ http://www.your-website.de/en$1 [L,R=301]
Anders Östberg’s picture

Thanks - I'm on Windows and IIS 6 though so I think that doesn't work for me.

EDIT: Maybe it will after all, I'll go look for a rewrite filter for IIS.

Anders Östberg’s picture

Well, I don't know if this is the best way to do it, I don't like to hack stuff I know little about, but I borrowed some code from another module with similar problems. Some added code in the redirect function in Rules checks for multilingual support and strips the language prefix before redirecting. This seems to solve my problem. Whether this has any unwanted side-effects or whether it works if you don't have a language prefix assigned to all languages I don't know at all. Please also note I have only tested this with Drupal 7, but as the borrowed code came from a Drupal 6 discussion I assume it works with that version as well.

Anyway, my modification of the file rules.module follows below:


...
function rules_drupal_goto_alter(&$path, &$options, &$http_response_code) {
  // Invoke a the page redirect, in case the action has been executed.
  if (isset($GLOBALS['_rules_action_drupal_goto_do'])) {
    list($url, $force) = $GLOBALS['_rules_action_drupal_goto_do'];

    if ($force || !isset($_GET['destination'])) {
      $url = drupal_parse_url($url);
      $path = $url['path'];

      // Added code starts
      if (module_exists('i18n')) {
        global $language;
        $len = strlen($language->prefix) + 1;
        $path = substr($path, $len);
      }
      // Added code ends

      $options['query'] = $url['query'];
      $options['fragment'] = $url['fragment'];
      $http_response_code = 302;
    }
  }
}
...

Anders Östberg’s picture

Title: Multilanguage page: Redirect rules action leads to doubled language prefix » Multilanguage page: Redirect rules action leads to doubled language prefix (D6 and D7)
TarekElTabey’s picture

Thanks Andres...

The code worked for me, not only it doesn't double the language prefix, but now redirects based on the language I'm using... thanks ;)

jumptrnr’s picture

anyone have a patch suggestion for Drupal 6 on this?

tobiberlin - had no luck with your suggestion - able to post your .htaccess?

Here is what I had...

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_URI} !=/server-status
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

# due to bug in Drupal
#RewriteRule ^fr/fr(.*)$ http://www.mysite.com/fr$1 [L,R=301]

lawrencey’s picture

Issue summary: View changes

Hi Everyone. Not sure if anyone is following up on this, I'd be interested in any further developments here. Many thanks for the code 'fix' posted in #4. I've managed to get this to work with a few tweaks.

I had the same requirement, realised that I was using Entity Translation module and also that there was a bug in the above addition for the case where the redirection was using the default language (and there was no language prefix). I made the following code changes to the rules module function detailed above.

function rules_drupal_goto_alter(&$path, &$options, &$http_response_code) {
// Invoke a the page redirect, in case the action has been executed.
if (isset($GLOBALS['_rules_action_drupal_goto_do'])) {
list($url, $force) = $GLOBALS['_rules_action_drupal_goto_do'];

if ($force || !isset($_GET['destination'])) {
$url = drupal_parse_url($url);
$path = $url['path'];

// Added code start
if (module_exists('entity_translation')) {
global $language;
$len = strlen($language->prefix);
if ($len > 0) {
$path = substr($path, $len + 1);
}
}
// Added code end

$options['query'] = $url['query'];
$options['fragment'] = $url['fragment'];
$http_response_code = 302;
}
}
}

Hope that helps and please send me feedback if you can spot any issues with this approach. Many thanks

baso’s picture

Thanks Anders for #4. Works for my multilingual Drupal 7.41 site.

arzuga’s picture

Anders Östberg solution #4 still good
thanks

TR’s picture

Title: Multilanguage page: Redirect rules action leads to doubled language prefix (D6 and D7) » Multilanguage page: Redirect rules action leads to doubled language prefix
Version: 6.x-1.5 » 7.x-2.x-dev

Drupal 6 is not supported any more, so this should be a D7 issue.

If you would like to see this fixed, please post a proper PATCH for this so it may be tested.

iamfredrik’s picture

The correct way is to set $options['language'] = FALSE;

TR’s picture

Status: Active » Needs work

We still need a patch here, and preferably also a test case to demonstrate the problem and the fix.