I've enabled System > Config > Web > Add Store Code to URLs and I've setup a new Store View for Canada (/ca/).

I'd like to ideally have example.com/ca/ load the Canada Store View, but still have example.com (without the default store code in there) for the default store.

I've noticed that the home page works just fine in this regard, but when I go into a product page, Magento automatically includes the store code in the URL.

The main reason that I'm hesitant to change our current URLs for our default store is just because I'd hate to see them lose any link juice. I know that theoretically as long as I setup 301 redirects, I should be fine, but I think I've read somewhere that a small amount of juice is still lost.

Also, I think this is probably somewhat better from a usability perspective. If the bulk of your traffic is to your default store, and your customers are used to the regular URL, why bother them with the additional /default/ (or /us/ or whatever) in the URL.

I've tried disabling Add Store Code to URLs and simply changing the Base URL for my Canada Store View to example.com/ca/, but that didn't seem to do anything. I'm assuming it needs the setting enabled in order to pick up the store code in the URL and do anything at all with it.


I didn't become happy using Add Store Code to URLs. The main reason was that we couldn't have several store views using the same language (see my question). Besides that I didn't like I have to use a bad store view code just because of the URL.

I did a small test using the frequently recommended "create a subfolder and create symlinks" tip and it may work. Please check if you like it.

  • Create a subfolder /ca/
  • Inside the subfolder create symbolic links to
    • ../app
    • ../errors
    • ../includes
    • ../index.php
    • ../js
    • ../lib
    • ../media
    • ../skin
    • ../var
    • (add other directories if you want/need to)
  • edit your vHost config for /ca/ (or copy .htaccess to /ca/ and edit it) to

    • Set the rewrite base:

      RewriteBase /ca/

    • Initialise the correct store view based on the URL. There are many ways to do it, one may be:

      RewriteCond %{REQUEST_URI} ^/ca/.* [NC,OR]
      RewriteCond %{REQUEST_URI} ^/ca$ [NC]
      RewriteRule .* - [E=MAGE_RUN_CODE:ca]
      RewriteCond %{ENV:REDIRECT_MAGE_RUN_CODE} (.+)
      RewriteRule .* - [E=MAGE_RUN_CODE:%1,E=MAGE_RUN_TYPE:store]`

It worked for me:

Creating folders and symlinks isn't fun but at least you don't have to edit core files.

  • 2
    You only have to make symlinks for media, js and skin and then edit the Mage class path to ../app/Mage.php. As far as I know that should be enough
    – Sander Mangel
    Sep 22 '13 at 19:13
  • 2
    Yes, if you want to edit core files. Sep 23 '13 at 7:55
  • @MatthiasZeis sorry for taking so long to accept! Sometimes I lose track of SE notifications and it's hard to mark them as unread. Feel free to ping me on twitter in the future if I take forever to mark an answer as accepted! At least with twitter you can favorite a tweet in order to remember to come back to it. Sorry and thanks again for the help here! Great answer! Feb 10 '14 at 22:58
  • No worries! I'm glad I could help you. Feb 11 '14 at 14:02
  • 2
    Great advise! Two possible simplifications: 1) Since you create separate vHost configurations or .htaccess files for the subdirectory, you can initialize the store view straightforward without conditions: SetEnv MAGE_STORE_VIEW ca. RewriteBase on the other hand is usually not necessary. 2) It should be enough to set symlinks to index.php and app, if you only set the Base Link URL to /ca/ and leave the default Base URL configuration Apr 22 '14 at 16:16

User clockworkgeek created the Magento-Store-Codes module just for this use-case.

I have tested this on CE with a single website setup with multiple store views, and it seemed to work perfectly!

See also: Magento : How to hide the default Store View code from the url


Based on the answer of mzeis and fschmengler's comment, here is a KISS way of doing it:

  1. Create a subdirectory ca: mkdir ca
  2. Create a symlink to the app directory: ln -s ../app/ ca/app
  3. Create a symlink to the index.php file: ln -s ../index.php/ ca/index.php
  4. Create a .htaccess file in the ca directory: touch ca/.htaccess with the following content:

    SetEnv MAGE_RUN_CODE ca
    RewriteEngine On
    RewriteBase /en/
    # solves the issue that the environment variable MAGE_RUN_CODE is only available as REDIRECT_MAGE_RUN_CODE
    # see http://stackoverflow.com/a/10128290/719023 for details
    RewriteOptions inherit
  5. Under System > Configuration > Web, set the Base Link URL to {{unsecure_base_url}}ca/ and {{secure_base_url}}ca/ respectively.

If, for some reason, the RewriteOptions inherit part is not possible for you, you can also simply copy the default mod_rewrite part into your sub-directory .htaccess file instead.

This solution should work as good as the one from mzeis, but is a lot smaller and easier.


another option is to use a subdomain per store. Then you just setup Apache to tell magento which "website/store" to use.

This way you can have multiple "stores" and "views" under the subdomain websites all in the same magento intall.

  • settings are in System>Configuration>General/Web
  • Unsecure . Base URL
  • Secure . Base URL
  • Cookie . Domain

this is the example.com store Apache config

<VirtualHost *:80>
    AllowEncodedSlashes On

    ServerName example.com
    ServerAdmin admin@example.com
    DocumentRoot /var/www/html/

    DirectoryIndex index.php

    <Directory "/var/www/html/" >
        AllowOverride All

    SetEnv MAGE_RUN_CODE "default"
    SetEnv MAGE_RUN_TYPE "Website"

this is the additional "ca" store Apache config

<VirtualHost *:80>
    AllowEncodedSlashes On

    ServerName ca.example.com
    ServerAdmin admin@example.com
    DocumentRoot /var/www/html/

    DirectoryIndex index.php

    <Directory "/var/www/html/" >
        AllowOverride All

    SetEnv MAGE_RUN_CODE "ca"
    SetEnv MAGE_RUN_TYPE "Website"

Juste add this to one of your system.xml file (in app/code/local module):


This way you can choose the option "Add Store Code to URLs" per store view.

  • You are able to select it. But are you sure, that it actually works? Dec 28 '15 at 12:16
  • Yes, tested on magento 1.9.x and magento EE 1.13.x
    – nverhoye
    Dec 29 '15 at 12:59
  • It would have been great if this actually worked, but I have not been able to make this work in a setting with one website and multiple store views. Tested on CE Feb 23 '16 at 15:33
  • not worked for me Apr 12 '17 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.