301 redirect in another language

edited February 2015 in Modules
What is the proper way to do 301 redirects in a multi-language site? I have two pages - "kompanija" in Lithuanian and "Company" in English, which are both of type "301_redirect", and both point to the same subpage that is labeled as the company's name, i.e. clicking on "company" in the navigation menu should point to "company/[company_name]", while clicking on "kompanija" should point to a different page, "kompanija/[company_name]".

This does work. However, the language segment is not appended, and so in case the user browses the page in the non-default language, the redirected page will not display anything!

What I'd need is for the redirect to point to "/lt/kompanija/[company_name]" and "/en/company/[company_name]" respectively.

I have modified the code of 301_redirect.php to this:

<?php $lang = $this->fuel->language->selected(); $redirect_to = $lang . "/" . $redirect_to; redirect($redirect_to, 'location', 301); ?>

It helps with redirecting the Lithuanian page, but not the English one. What might be the reason?

I have the following in My_fuel.php:

$config['languages'] = array( 'lt' => 'Lithuanian', 'en' => 'English', 'ru' => 'Russian', ); $config['language'] = 'lt'; $config['language_mode'] = 'segment'; $config['add_language_to_site_url'] = TRUE; $config['language_force_default_to_site_url'] = TRUE;

Edit: renaming the location of the actual "company/[name]" page to "company/[name]23123123" and setting the redirect to yet another "company/[name]210101" still has "company" point to the old "company/[name]"! I cleared the cache. Wonder what might be causing this?

Comments

  • edited 3:19PM
    Does the "company/[name]210101" page actually exist in the CMS as a page and you can verify that the $redirect_to variable set is "company/[name]210101" (e.g. you can just put a debug exit($redirect_to); in the 301_redirect.php layout.

    Also, there is a cookie that is set by default for the language being used that you may want to clear as well. To turn off setting the cookie, you can use $CI->fuel->language->use_cookies = FALSE;
  • edited February 2015
    Nope, it doesn't exist. It somehow still caches the other page. Or maybe just goes to the first 'child' page in the navigation tree, I don't know.

    Actually... wait, I just tried it out in IE (was previously using FF). It's probably a local caching issue. The $redirect_to variable actually holds the correct value of "company/[name]".

    Technically though shouldn't it also have the language segment before that? I could just attach it in the 301_redirect.php file but there might be another way?

    site_url() works fine, outputs the segment, but redirection seems to need this workaround.
Sign In or Register to comment.