TYPO3 fully supports the making of multilanguage web sites. Everyone know the L URL parameter. But what if you want to have a separate domain for each language and keep a single page tree? Until recently it was not easy and required certain TYPO3 black magic. In this article I will describe how to do it in 5 minutes (or less!) and give you a bonus: better site position in Google.

Typically when user switches to another language, the URL changes to contain L var ('&L=1'). In case of RealURL it looks better, URL will become http://example.com/en/. This is nice looking. So far, so good.

The problem is that Google and other search engines prefer domains from the user's domain zone. If relevancy is the same, Google will prefer "es" domain to "com" domain for Spain and "de" domain for Germany. It becomes essential to have domains in the corresponding country for better search engine optimization. Registering domains is easy but how to make TYPO3 use them and keep the single page tree?

Solving this task means removing language segments from URL and converting http://example.com/de/mypage to http://example.de/mypage/.

It is possible to have language domains with TYPO3 after doing certain non–trivial TypoScript magic. Alternatively it is possible with some coding. However there is a much better, faster and more simple solution. It is brought to you by RealURL (surprise, surprise!)

RealURL 'language domains' feature

Starting from version 1.5.0 RealURL supports 'language domains' feature. It does exactly what was described above: it converts http://example.com/de/mypage to http://example.de/mypage/ transparently and without other major efforts in TYPO3. This feature needs only a small adjustment in the RealURL configuration.

Configuration requirements for language domains

To enable language domains you must have the following in you RealURL configuration:

  • language variables defined in the preVars section. See 'Making preVar section' in the 'RealURL made easy: part 1' on this site.
  • a special _DOMAINS configuration.

There is no problem with the first part. Everyone knows how to do it. The second part is new. Let's master it!

_DOMAINS RealURL configuration

_DOMAINS configuration defines how to transform a value of the URL parameter to the domain name. In other words, it links &L=0 to the example.de and &L=1 to the example.es.

Suppose that languages are configured like this in preVars:

'preVars' => array(
    array(
        'GETvar' => 'L',
        'valueMap' => array(
            'de' => 0,
            'es' => 1
        ),
    ),
),

Now we need to define how this preVar maps to domains. Here it is:

'_DOMAINS' => array(
    'encode' => array(
        array(
            'GETvar' => 'L',
            'value' => '0',
            'useConfiguration' => 'example.com',
            'urlPrepend' => 'http://example.de'
        ),
        array(
            'GETvar' => 'L',
            'value' => '1',
            'useConfiguration' => 'example.com',
            'urlPrepend' => 'http://example.es'
        )
    ),
    'decode' => array(
        'example.de' => array(
            'GETvars' => array(
                'L' => '0',
            ),
            'useConfiguration' => 'example.com'
        ),
        'example.es' => array(
            'GETvars' => array(
                'L' => '1',
            ),
            'useConfiguration' => 'example.com'
        )
    )
)

What does it do?

The first part is for encoding URLs. It tells that for L=0 RealURL should prepend http://example.de to the URL (notice: no slash in the end!). For L=1 RealURL should prepend http://example.es to the URL. Simple, isn't it?

The second part is for decoding. It tells RealURL what L to set when user comes for the corresponding domain. Also simple.

And the final addition to the configuration is:

$TYPO3_CONF_VARS['EXTCONF']['realurl']['example.de'] =
    $TYPO3_CONF_VARS['EXTCONF']['realurl']['example.es'] = 'example.com';

Do not forget to add two new domain records for your language domains in the List module.

That's it! A couple of lines in the RealURL configuration and you have language domains without any mangling with TypoScript or hooks!

Life is good! Enjoy!