|
This whole business is very much hard-coded into the 0.6.12383 build. For the time being, I’ve solved it the way described below. There may be more elegant solutions, and the “official” way will probably be completely different, but for now this works for me.
This solution ignores the Default URL settings in Admin > System > Configuration > Web, but so does the Magento code in this build.
This solution doesn’t support multiple languages - it shows the same “not-found” page regardless of the language setting. So does the Magento code in this build.
INDEX FILE
I modified the index file to call the right store depending on the URL. This allows me to park additional URLs on top of the base Magento URL.
My index file also sets a global array through which I can pass parameters into Magento.
// Remove the port number, if any, from the host name $httpHost = explode(':', $_SERVER['HTTP_HOST']);
// Split the full domain name into its parts $domainParts = explode(".", $httpHost[0]);
// Remove a leading "www" since it is not a true subdomain if ($domainParts[0] == "www") { array_shift($domainParts); } // Determine the highest offset $domainPartsUBound = sizeof($domainParts) - 1;
// Assemble the base domain name (e.g. microsoft.com) $domainName = $domainParts[$domainPartsUBound-1] . "." . $domainParts[$domainPartsUBound];
// Re-assemble the subdomain name (e.g. support.microsoft.com) without the "www" $subdomainName = $domainParts[0]; for ($x=1; $x <= $domainPartsUBound; $x++) { $subdomainName = $subdomainName . "." . $domainParts[$x]; }
// Determine what store this is for switch($domainName) { case 'firstsite.com': $userGlobals['home'] = "mbfa-home"; $userGlobals['no-route'] = "mbfa-en-not-found"; $userGlobals['favicon'] = "mbfa.ico"; $store = "mbfaen"; break; case 'demosite.com': $userGlobals['home'] = "home"; $userGlobals['no-route'] = "no-route"; $userGlobals['favicon'] = "favicon.ico"; $store = "base"; break; }
require 'app/Mage.php'; Mage::run($store);
INDEXCONTROLLER.PHP
The IndexController.php script uses hard-coded names for the home and no-route pages. I simply modified it to use the setting from the index file instead.
The path for this file is /app/code/core/Mage/Cms/controllers/.
class Mage_Cms_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction($coreRoute = null) { global $userGlobals; // Magnus if (isset($userGlobals['home'])) { Mage::getSingleton('cms/page')->load($userGlobals['home']); } else { Mage::getSingleton('cms/page')->load('home'); } $this->_forward('view', 'page'); } public function noRouteAction($coreRoute = null) { global $userGlobals; // Magnus if (isset($userGlobals['no-route'])) { Mage::getSingleton('cms/page')->load($userGlobals['no-route']); } else { Mage::getSingleton('cms/page')->load('no-route'); } $this->_forward('view', 'page'); } }
|