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!
Comments
thanks a lot for that tut, I will try it!
ps: can you please modify the captcha to just show numbers?
[globalString = IENV:HTTP_HOST = www.domain.com]
config.baseURL = http://www.domain.com/
config.sys_language_uid = 0
config.language = en
config.locale_all = en_EN
[globalString = IENV:HTTP_HOST = www.domain.nl]
config.baseURL = http://www.domain.nl/
config.sys_language_uid = 1
config.language = nl
config.locale_all = nl_NL
[end]
This also did the trick (maybe we needed just a little bit more). But we weren't able to use the language selector to only switch the L parameter. Our language selector was a link to the proper domain. Which of course will loose the functionality as well that we cannot directly view the page in another language if we change the language.
This makes stuff easier. Thanks for sharing.
There is some debate on wether google still prefers the local domains... Don't know where they are now though..
First the URL translation field is not showing. For that I had to modified the last line in the ext_tables.php as follow:
t3lib_extMgm::addToAllTCAtypes('pages_language_overlay', 'tx_realurl_pathsegment', (t3lib_div::compat_version('4.2') ? '' : '2,4,254') . '', 'after:nav_title');
2. I'm not able stil to make the multiple domains with the path translation work correctly together. When one is working the other one is not. I found that if I don't define the _DOMAINS array it work more or less correctly, but the function typolink don't use the domains. That is ok as long as I don't try to make any cross language link.
I would apreciate if you can give me a hand with this second issue.
Thanks.
1. Should one still use the "Redirect to:"-field in the foreign domain-records to reach "example.com/de/" or not?
2. How should one write the _DOMAINS-rules to handle domains both with and without www-prefix? Or is this handled by only using "domain.tld"?
3. Should the baseurl still be set to http://www.domain.com/ or are there special-cases depending on which language?
I guess a full realurl_conf.php-example with a little typoscript-example would help out tremendously.
Best regards,
I worked it around in this way:
1) Don't use the 'encode' rule
2) Change the preVars rule this way:
'preVars' => array (
array (
'GETvar' => 'L',
'valueMap' => array (),
'noMatch' => 'bypass'
),
),
of course you lose the possibility to switch domain just changing L, but it is a minor problem compared to the untranslated path.
PS: Dmitry thanks for your great blog!
Thank you!
siteA-germanname.com
siteA-frenchname.com
siteB-samenameforbothlanguages.com
I would appreciate a hint on how to solve this (with _DOMAINS feature) very much!
Thanks for all the work
Urs
But, like Urs, I am challenged by a multi-domain-multi-language single-tree single installation. Something like:
domainA.de/dk --> domainA.dk/
domainA.de/de --> domainA.de/
domainA.de/en --> domainA.com/
domainB.de/dk --> domainB.dk/
domainB.de/de --> domainB.de/
domainB.de/en --> domainB.com/
Could anybody solve a similar problem using realurl and the _DOMAINS feature?
It works, but I'm using sr_language_menu and it work incorrect - it always link to main language.
<code class="php">
'preVars' => array(
array (
'GETvar' => 'L',
'valueMap' => array (),
'noMatch' => 'bypass'
),
),
</code>
to my RealURL configuration to remove &L= param from URL. Can please someone confirm that this is the right way?
here is my config
http://cht.net.ua/typo3conf/realurl_autoconf.txt
for
http://cht.net.ua
but i cant understand how to config my site for subdomains proper.
Now all links are generated properly but not resolve properly.
can you drop config for multilanguage subdomain site?
Add a comment
All fields in this form are required!