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.
In regards to your second question:
I would avoid domain names with Umlauten - Full Stop.
If you were so free to purchase and use such a domain, I would also buy the domain without umlaute and redirect the umlaute-domain to the one without
eg: geldsüchtling.com => geldsuechtling.com
this one without any umlaute should handle all your functionality andhost your site - the other is simply a 'bonus' domain for your business which should NOT handle or host anything, just redirect.
Umlaut support in domain names is pretty bad and i can not recommend it - and yes, I have a few stores on domains where we have done the above because actually using such a domain is a right pain.
Best Answer
I've done a setup with Magento 2.2 and nginx before, but with subdomains instead of folders.
So the setup was:
etc.
This is a modified version of the setup, maybe it helps you getting started. Another/additional idea: Create 2 nginx config files (one for each domain) and use
alias
for the subfolders?I am not an nginx expert but got my setup running in the end :)