Skip to content

Instantly share code, notes, and snippets.

@rodrigowebjump
Last active August 29, 2015 14:27
Show Gist options
  • Save rodrigowebjump/526b5385bc8f40a32b16 to your computer and use it in GitHub Desktop.
Save rodrigowebjump/526b5385bc8f40a32b16 to your computer and use it in GitHub Desktop.
[magento] multidomain-multistore-multistoreview setup with visible language codes

Use these snippets to setup a magento installation with the following structure:

No additional htaccess/apache rewrites required! Make shure you stick to the naming convention mentioned above under System/Manage Stores! Note: A more reliable approach (especially when using proxies/load-balancers e.g. in a setup with varnish upfront) would be to make use of the environment variables in your nginx/apache/php-fpm vhosts and switch them accordingly

fastcgi_param MAGE_RUN_TYPE store;
fastcgi_param MAGE_RUN_CODE domain1_en;

For this to work properly, you also have to manually adjust the settings at

  • website: domain / storeview: domain_en / System/Configuration/Web/Unsecure: Base Link Url -> {{unsecure_base_url}}en/
  • website: domain / storeview: domain_en / System/Configuration/Web/Secure: Base Link Url -> {{secure_base_url}}en/
  • website: domain / storeview: domain_de / System/Configuration/Web/Unsecure: Base Link Url -> {{unsecure_base_url}}de/
  • website: domain / storeview: domain_de / System/Configuration/Web/Secure: Base Link Url -> {{secure_base_url}}de/
  • website: domain1 / storeview: domain1_en / System/Configuration/Web/Unsecure: Base Link Url -> {{unsecure_base_url}}en/
  • website: domain1 / storeview: domain1_en / System/Configuration/Web/Secure: Base Link Url -> {{secure_base_url}}en/
  • website: domain1 / storeview: domain1_de / System/Configuration/Web/Unsecure: Base Link Url -> {{unsecure_base_url}}de/
  • website: domain1 / storeview: domain1_de / System/Configuration/Web/Secure: Base Link Url -> {{secure_base_url}}de/
  • website: domain2 / storeview: domain2_en / System/Configuration/Web/Unsecure: Base Link Url -> {{unsecure_base_url}}en/
  • website: domain2 / storeview: domain2_en / System/Configuration/Web/Secure: Base Link Url -> {{secure_base_url}}en/
  • website: domain2 / storeview: domain2_de / System/Configuration/Web/Unsecure: Base Link Url -> {{unsecure_base_url}}de/
  • website: domain2 / storeview: domain2_de / System/Configuration/Web/Secure: Base Link Url -> {{secure_base_url}}de/
<?php
include_once $_SERVER['DOCUMENT_ROOT'].'/storemapping.php';
# replace the REQUEST_URI such as /en/blah.html with /blah.html
$_SERVER['REQUEST_URI'] = preg_replace("#^/$lang(/.*)#i",'$1',$_SERVER['REQUEST_URI']);
# we want our /lang/ urls to take priority over store querystrings
# but not if we are in the admin panel
if ( ! preg_match('#^/index.php/admin/#i',$_SERVER['REQUEST_URI']) ) {
$_GET['___store'] = $store;
}
umask(0);
Mage::run($store,'store');
<?php
if ( strpos($_SERVER['HTTP_HOST'], "www.domain1.tld") !== false ) {
$store='store1';
} else if( strpos($_SERVER['HTTP_HOST'], "www.domain2.tld") !== false ) {
$store='store2';
} else {
$store='store'; # which is the default store of your installation (www.domain.tld)
}
if ( strpos($_SERVER['REQUEST_URI'], "/de/") !== false ) {
$lang = 'de';
} else if ( strpos($_SERVER['REQUEST_URI'], "/es/") !== false ) {
$lang = 'es';
} else {
$lang = 'en'; # which is the default language of the default store of your installation (/)
}
$store .= '_' . $lang;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment