Magento remove store code for default store view

2019-03-02 10:11发布

问题:

I've Magento multilanguage store and I need to add store code to url. In this path System > Configuration > Web > Url Option > Add Store Code to Urls I've turn ON, then I see in url as such site.com/en (default), site.com/br (brazillian).

How I can remove EN in default site.com/en and get for default store site.com without EN path??

回答1:

I have made a new extension available on GitHub that allows you to hide the default store code from URLs.

More information here: https://github.com/jreinke/magento-hide-default-store-code



回答2:

By Default magento will only allow you to change this config option for the whole setup, you can't change it on a by store basis.

You can possibly update magento to allow you to specify different settings for this option per website to allow you to do what you need:

app/code/core/Mage/Core/etc/system.xml

<use_store translate="label">
    <label>Add Store Code to Urls</label>
    <frontend_type>select</frontend_type>
    <source_model>adminhtml/system_config_source_yesno</source_model>
    <backend_model>adminhtml/system_config_backend_store</backend_model>
    <sort_order>10</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>0</show_in_website>
    <show_in_store>0</show_in_store>
</use_store>

Note, you should not change this file directly, but overrie it in your own module. You can find many tutorials out there for helping to override core magento configs and files.

if you updated the scope settings:

 <show_in_default>1</show_in_default>
 <show_in_website>1</show_in_website>
 <show_in_store>1</show_in_store>

this will allow you to change the "Add Store Code to Urls" for each website/store front in the admin section.

Now you can try and set "Add Store Code to Urls" = NO for the default store and "Add Store Code to Urls" = YES for the others.

Please note I have not tested this, so I would not do this on a live store :)



回答3:

I have an alternative solution that worked well too.

Copy app/code/core/Mage/Catalog/Block/Widget/Link.php to app/code/local/Mage/Catalog/Block/Widget/Link.php

Search for (line 91 in Magento 1.7.x / line 100 in Magento 1.9.x)

$this->_href = $this->_href . $symbol . "___store=" . $store->getCode();

And modify to

$this->_href = $this->_href;

Upload and save your changes and you'll now not have your widget (dynamically) inserted links getting appended with ?___store=default.

Credit: DesignHaven