Different storeviews or websites in subfolders
It's very easy to serve multiple domains/paths based on URLs. As mentioned, the easiest setup (configuration-only) is possible when the unique core/store
codes can be used in the path as subfolders. This requires one of the following:
- Visitors are linked to the correct subfolder path initially
- Visitors are served a landing page from which they select their store and receive a cookie
- Some mechanism is used to set the run type and run code prior to PHP handling the response
Regarding #3: since 1.4 Magento, made it possible to allow the Web server to determine the running context (website or store) as well as the particular code which should be used. From index.php:
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
Mage::run($mageRunCode, $mageRunType);
Whereas environment variables are used to initialize the application, it's possible to influence the system prior to PHP even spinning up. With Apache and mod_rewrite
this can be done for subfolders with a bit of trickery:
RewriteCond %{REQUEST_URI} ^/de/$
RewriteRule .* - [E=MAGE_RUN_CODE:deutsch]
RewriteCond %{ENV:REDIRECT_MAGE_RUN_CODE} (.+)
RewriteRule .* - [E=MAGE_RUN_CODE:%1]
Apache is twitchy with environment variables and subfolders, as demonstrated by this excellent SO answer. The initial two lines result in $_SERVER["REDIRECT_MAGE_RUN_CODE"] = 'deutsch';
while the latter two lines provide the needed $_SERVER["MAGE_RUN_CODE"] = 'deutsch';
. There are numerous other tricks, but the above has bitten me before.
The end goal should be initial detection as much as is reasonable (geoip + multi-language concerns) while getting the user to set the store cookie which can be used to bypass/step through the logic in subsequent requests.
If the indented URLs (subfolders) can have the same name like the store codes (why not?), you can simply enabled Configuration > Web > Url options > Add Store Code to Urls
.
we ended up doing exactly that
We verified with Enterprise support that the best way to do this is by creating subfolders.
We ended up doing it like this:
- Create a "languagefolders" directory
- Created a copy of index.php inside the directory along with an adjusted .htaccess and symlinks to the Magento folders (app/, errors/, ...)
- Created symlinks "de", "en" etc. inside the Magento root directory pointing to the "languagefolders" directory
This way we can add a new language by creating a new symlink (e.g. "fr").
In the backend we set the store base url
to domain.com/en
If you use nginx an update is necessary to your location processing to process index.php also in the new sub folder. This needs to be done for every new translation folder