Magento 1 Store Code in URL for All Store Views Except Default

magento-1multistore

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.

Best Answer

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.

Related Topic