Craft CMS Multilingual/Multidomain base setup

<?php /** * General Configuration * * All of your system's general configuration settings go in here. * You can see a list of the default settings in craft/app/etc/config/defaults/general.php */ $config = array( '*' => [ 'siteUrl' => 'http://' . $_SERVER['SERVER_NAME'] . '/', ], '.it.local' => [ 'locale' => 'it_it' ], '.nl.local' => [ 'locale' => 'nl_nl' ], '.it.dev' => [ 'locale' => 'it_it', 'devMode' => true ] ); $config['*']['baseUrl'] = $config['*']['siteUrl']; foreach ($config as $key => $settings) { if (stristr($_SERVER['SERVER_NAME'], $key)) { define('CRAFT_LOCALE', $settings['locale']); } } return $config;
Make sure all your domains point to the same public/www directory. Don't set the locale (CRAFT_LOCALE) in the index, but let the configuration handle it for you.

With this setup, you can point multiple domains to your Craft setup:

craft.it.local
craft.nl.local
craft.it.dev

The configuration sets the siteUrl based on $_SERVER['SERVER_NAME'] and copies it to the baseUrl setting. Set global settings in the '*' array; overrule for specific domains.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.