Multi-language support
This article relates to older versions of Contrexx < v3
Contents
Virtual language directories
Introduction
You can tell Contrexx that it should use so called virtual language directories instead of the URL modifier langId. For instance the URI http://www.contrexx.com/index.php?section=shop&langId=2 would then be represented as http://www.contrexx.com/en/index.php?section=shop.
Important: This feature is still experimental. That means it works well in general, but there might still be one or the other unknown inconsistence within the system. On the other hand it has only be tested with the Apache web server. This is the reason why this feature can't yet be activated through a configuration option in the backend.
Configuration
Set up the rewrite engine
You need a rewrite engine that translates the virtual URIs into normal URIs (ones without containing the virtual language directory). The rewrite engine must also set the server variable REDIRECT_CONTREXX_LANG_PREFIX to the ISO-639-1 specified code of the requested language.
You can use one of the following rewrite configurations depending on the web server you are using.
Apache mod_rewrite example
This example can be used when using the Apache modul mod_rewrite.
Place the following directives in the file .htaccess (create it if it doesn't already exists) in the directory where Contrexx is installed. Replace the URL www.example.com with your own.
RewriteEngine On #################### # URI redirections # #################### # Move to www.example.com (we don't wanna serve this page without the subdomain www) RewriteCond %{HTTP_HOST} !^www.example.com [NC] RewriteRule ^.*$ http://www.example.com%{REQUEST_URI} [L,NC,R=301] # If so, then load language defined by cookie RewriteCond %{REQUEST_URI} ^/$ RewriteCond %{HTTP_COOKIE} langId=([a-z]{2}) RewriteRule ^.*$ /%1%{QUERY_STRING} [L,NC,R=301] # Add a trailing slash to the request uri if /de was requested without one RewriteCond %{REQUEST_URI} ^/(de|en|fr|it|da|ru|zh)$ RewriteRule ^.*$ /%1/ [L,NC,R=301] #################################### # Request the appropriate language # #################################### # German RewriteCond %{REQUEST_URI} ^/de/index.php|^/de(/)?$ RewriteCond %{QUERY_STRING} !langId [OR] RewriteCond %{QUERY_STRING} langId=1 RewriteRule ^de/?.*$ /index.php?%{QUERY_STRING}&langId=1 [L,NC,E=CONTREXX_LANG_PREFIX:de] # English RewriteCond %{REQUEST_URI} ^/en/index.php|^/en(/)?$ RewriteCond %{QUERY_STRING} !langId [OR] RewriteCond %{QUERY_STRING} langId=2 RewriteRule ^en/?.*$ /index.php?%{QUERY_STRING}&langId=2 [L,NC,E=CONTREXX_LANG_PREFIX:en] # French RewriteCond %{REQUEST_URI} ^/fr/index.php|^/fr(/)?$ RewriteCond %{QUERY_STRING} !langId [OR] RewriteCond %{QUERY_STRING} langId=3 RewriteRule ^fr/?.*$ /index.php?%{QUERY_STRING}&langId=3 [L,NC,E=CONTREXX_LANG_PREFIX:fr] # Italian (deactivated) #RewriteCond %{REQUEST_URI} ^/it/index.php|^/it(/)?$ #RewriteCond %{QUERY_STRING} !langId [OR] #RewriteCond %{QUERY_STRING} langId=4 #RewriteRule ^it/?.*$ /index.php?%{QUERY_STRING}&langId=4 [L,NC,E=CONTREXX_LANG_PREFIX:it] # Danish RewriteCond %{REQUEST_URI} ^/da/index.php|^/da(/)?$ RewriteCond %{QUERY_STRING} !langId [OR] RewriteCond %{QUERY_STRING} langId=5 RewriteRule ^da/?.*$ /index.php?%{QUERY_STRING}&langId=5 [L,NC,E=CONTREXX_LANG_PREFIX:da] # Russian (deactivated) #RewriteCond %{REQUEST_URI} ^/ru/index.php|^/ru(/)?$ #RewriteCond %{QUERY_STRING} !langId [OR] #RewriteCond %{QUERY_STRING} langId=6 #RewriteRule ^ru/?.*$ /index.php?%{QUERY_STRING}&langId=6 [L,NC,E=CONTREXX_LANG_PREFIX:ru] # Chinese RewriteCond %{REQUEST_URI} ^/zh/index.php|^/zh(/)?$ RewriteCond %{QUERY_STRING} !langId [OR] RewriteCond %{QUERY_STRING} langId=7 RewriteRule ^zh/?.*$ /index.php?%{QUERY_STRING}&langId=7 [L,NC,E=CONTREXX_LANG_PREFIX:zh] ######################## # Serving normal files # ######################## # Request language specific sitemap.xml RewriteCond %{REQUEST_URI} ^/(de|en|fr|it|da|ru|zh)/sitemap.xml$ RewriteRule ^(de|en|fr|it|da|ru|zh)/.*$ /sitemap_$1.xml [L,NC] # Request normal files like images or style sheets RewriteCond %{IS_SUBREQ} false RewriteRule ^(?:de|en|fr|it|da|ru|zh)/(.*)$ /$1 [L,NC,R=301] # Move to index.php if the requested file doesn't exist RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ http://www.example.com [L,NC,R=301]
Internet Information Services
Not example available yet. See Rewrite Engines for IIS
Active the option in Contrexx
You have to active this option manually by doing the following tasks:
- Execute the following SQL statement in the Backend section Database Manager > SQL:
UPDATE `DBPREFIX_settings` SET `setvalue` = 'on' WHERE `setname` = 'useVirtualLanguagePath';
Replace DBPREFIX_ with the appropriate prefix. - Go to the section Basic Configuration and write the configuration file by invoking the Save button.