We now properly set MAGE_RUN_TYPE and MAGE_RUN_CODE

We’ve corrected an error in our Nginx configuration. We used to always set MAGE_RUN_TYPE to “store” and MAGE_RUN_CODE to “default” in your Magento environment.

Luk van den Borne asked us to change this behaviour because it is incorrect. It leads to notorious problems with getting error 404 codes when requesting URLs that are not configured as a base_url in any storeview. This has lead to some very wild Nginx configuration tweaking (attempts) by customers and our support.

So we’ve fixed this by only setting them when needed.



The solution is actually quite simple. The best behaviour is to only set these variables if the user wants to. So out of the box, the system now works as follows:

  1. Nginx does not set any MAGE_RUN_TYPE or MAGE_RUN_CODE by default.
  2. Magento’s bundled index.php sees that these variables are missing and defaults to “store” and “”.
  3. Mage::run then resolves to rendering the default storeview in store mode.

If you want to modify this behaviour, you have two options:

  1. Use the nginx config file http.magerunmaps: this allows you to specify which codes to run for which URL.
  2. Code your own code in index.php.

We like the http.magerunmaps solution, because it allows you to upgrade to new Magento versions more easily.