├── README.md └── app ├── code └── community │ └── Bubble │ └── HideDefaultStoreCode │ ├── Helper │ └── Data.php │ ├── Model │ ├── Observer.php │ └── Store.php │ └── etc │ ├── config.xml │ └── system.xml └── etc └── modules └── Bubble_HideDefaultStoreCode.xml /README.md: -------------------------------------------------------------------------------- 1 | # This module allows you to hide default store code from URLs 2 | 3 | ![Magento Hide Default Store Code](http://i.imgur.com/FVuZL5f.png) 4 | 5 | ## Feature 6 | 7 | http://www.example.com/default/shoes.html 8 | 9 | _becomes_ 10 | 11 | http://www.example.com/shoes.html 12 | 13 | ## Installation 14 | 15 | ### Magento CE 1.8.x, 1.9.x 16 | 17 | Install with [modgit](https://github.com/jreinke/modgit): 18 | 19 | $ cd /path/to/magento 20 | $ modgit init 21 | $ modgit clone hide_store https://github.com/jreinke/magento-hide-default-store-code.git 22 | 23 | or download package manually: 24 | 25 | * Download latest version [here](https://github.com/jreinke/magento-hide-default-store-code/archive/master.zip) 26 | * Unzip in Magento root folder 27 | * Clear cache 28 | * Logout from admin then login again to access module configuration 29 | 30 | ## Configuration 31 | 32 | * Go to "System > Configuration > Web > Url Options" 33 | * Enable both "Add Store Code to Urls" and "Hide Default Store Code" options 34 | * Clear cache 35 | 36 | Other Magento extensions available on [www.bubbleshop.net](https://www.bubbleshop.net/) -------------------------------------------------------------------------------- /app/code/community/Bubble/HideDefaultStoreCode/Helper/Data.php: -------------------------------------------------------------------------------- 1 | isEnabled(); 28 | } 29 | } -------------------------------------------------------------------------------- /app/code/community/Bubble/HideDefaultStoreCode/Model/Observer.php: -------------------------------------------------------------------------------- 1 | _canRewriteUri()) { 16 | /** @var $front Mage_Core_Controller_Varien_Front */ 17 | $front = $observer->getEvent()->getFront(); 18 | $request = $front->getRequest(); 19 | $requestUri = $request->getRequestUri(); 20 | $requestUri = str_replace($request->getServer('SCRIPT_NAME'), '', $requestUri); 21 | $requestUri = trim($requestUri, '/'); 22 | $pieces = explode('/', $requestUri); 23 | if (!in_array($pieces[0], $this->_getStoreCodes())) { 24 | $storeCode = $this->_getDefaultStore()->getCode(); 25 | if (!empty($storeCode)) { 26 | $requestUri = $request->getServer('SCRIPT_NAME') . '/' . $storeCode . '/' . $requestUri; 27 | $request->setRequestUri($requestUri); 28 | $request->setActionName(null); 29 | } 30 | } 31 | } 32 | } 33 | 34 | /** 35 | * @return bool 36 | */ 37 | protected function _canRewriteUri() 38 | { 39 | return !Mage::app()->getStore()->isAdmin() 40 | && Mage::helper('bubble_hdsc')->hideDefaultStoreCode(); 41 | } 42 | 43 | /** 44 | * @return array 45 | */ 46 | protected function _getStoreCodes() 47 | { 48 | $storeCodes = array(); 49 | $default = $this->_getDefaultStore(); 50 | foreach (Mage::app()->getStores() as $store) { 51 | /** @var $store Mage_Core_Model_Store */ 52 | if ($store->getId() != $default->getId()) { 53 | $storeCodes[] = $store->getCode(); 54 | } 55 | } 56 | 57 | return $storeCodes; 58 | } 59 | 60 | /** 61 | * @return Mage_Core_Model_Store 62 | */ 63 | protected function _getDefaultStore() 64 | { 65 | return Mage::app()->getDefaultStoreView(); 66 | } 67 | } -------------------------------------------------------------------------------- /app/code/community/Bubble/HideDefaultStoreCode/Model/Store.php: -------------------------------------------------------------------------------- 1 | isAdmin() || !$helper->hideDefaultStoreCode()) { 19 | return parent::getStoreInUrl(); 20 | } 21 | 22 | return $helper->hideDefaultStoreCode() 23 | && $this->getCode() !== Mage::app()->getDefaultStoreView()->getCode(); 24 | } 25 | } -------------------------------------------------------------------------------- /app/code/community/Bubble/HideDefaultStoreCode/etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 1.0.0 6 | 7 | 8 | 9 | 10 | 11 | Bubble_HideDefaultStoreCode_Helper 12 | 13 | 14 | 15 | 16 | Bubble_HideDefaultStoreCode_Model 17 | 18 | 19 | 20 | Bubble_HideDefaultStoreCode_Model_Store 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | bubble_hdsc/observer 29 | onFrontInitBefore 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 0 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /app/code/community/Bubble/HideDefaultStoreCode/etc/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | select 11 | adminhtml/system_config_source_yesno 12 | 11 13 | 1 14 | 0 15 | 0 16 | http://www.example.com/default/
becomes
http://www.example.com/]]>
17 | 18 | 1 19 | 20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | -------------------------------------------------------------------------------- /app/etc/modules/Bubble_HideDefaultStoreCode.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | community 7 | 8 | 9 | 10 | --------------------------------------------------------------------------------