A client wants his multistore shop to be set up like this:
- http://www.domain1.org/de/ -> website 1, store view 1
- http://www.domain1.org/en/ -> website 1, store view 2
- http://www.domain1.ch/de/ -> website 2, store view 3
- http://www.domain1.ch/fr/ -> website 2, store view 4
- http://www.domain1.ch/it/ -> website 2, store view 5
- …
This is an example but there may be many more different subfolders.
What is the best approach to handle different subfolders for different store views / websites?
I know that one solution is to create subfolders called de
, en
etc. and copy the index.php and .htaccess into the corresponding subfolders.
There also may be some workarounds (symlinks for index.php, vHost configuration instead of using .htaccess) to minimise file duplication but I'd like to find a solution where I don't have to do any changes in the file system but just handle everything by configuration.
UPDATE
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").
Best Answer
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: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:
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: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.