Step 4 – Create a multilanguage site with CodeIgniter

Well, the site will be a multilanguage one, so let’s think about how would we go creating the infrastructure for this.

The easiest and also recommended way for SEO ( is for the links to content to look like below:

Also, for default language, it should look as below:

Inside the header of html pages we should have a hreflang attribute for every translation including itself (

<link rel=”alternate” hreflang=”en” href=”” />
<link rel=”alternate” hreflang=”ro” href=”” />
<link rel=”alternate” hreflang=”fr” href=”” />

Well… it gets a bit complicated, doesn’t it?

Let’s start by creating the admin area for languages.


  1. Hi,

    First of all, thank you for this tutorial.

    You talk about “hreflang attribute for every translation” like:

    I can’t find any information about this in your tutorial. Could you explain how two achieve this?


    1. Hello. Thank you for your kind words. Once you reach step 8, you will see that you can retrieve the id of a post and with that you should retrieve all the slugs for the languages of that particular post. From there on, I assume it’s easy to iterate through them so that you will output those hreflangs 🙂

      1. Thanks for your fast answer. But what happens with methods that we have manage on routes files?

        $controllers_methods = array(
        ‘en’ => array(
        ‘welcome/list’ => ‘welcome/list’,
        ‘welcome’ => ‘welcome’
        ‘fr’ => array(
        ‘bienvenu/list’ => ‘welcome/list’,
        ‘bienvenu’ => ‘welcome’

        1. Those are for exemplification. They simply tell CodeIgniter what controllers and methods to serve when someone enters through a custom language url. What I mean by this is: If you are a spanish guy (as a visitor of a site), you wouldn’t like to go to a url like “” and be served a page in your language. You would want the url to also be in spanish, like “”. So if a visitor receives content in their language, why not also make the URLs in their language? Now… as a developer, would that mean that you’d have to duplicate controllers and methods? No. You create ONE controller and its methods and serve the same logic in different languages. And in the views, instead of writing directly the strings, you would use the language files in order to serve the “static” content in the appropriate language.

Leave a Reply

Your email address will not be published. Required fields are marked *

No spam? * Time limit is exhausted. Please reload CAPTCHA.