I have a very specific question about url rewrites.
Basicly I want an url to do rewriting to a product unindependent of the current store (so it has to be a unique url).
Given is following setup and requirements:

  • Add store code to urls: Yes (can not be changed anymore!)
  • URLs are unique (this is given and verified)
  • Rewrite request url (eg): a_shortcut
  • Rewrite target url (eg): catalog/product/view/id/[id]
  • URL has to be unique! So for example "a_shortcut" should always redirect to the english store whereas "eine_abkuerzung" should always redirect to the german store

Any ideas on how to solve this problem with switching the store and doing a rewrite at the same time? Any thoughts on that are very welcome!

1 Answer 1


During the Mage_Core_Controller_Varien_Front::dispatch() process, Mage_Core_Model_Url_Rewrite::rewrite() ends up calling Mage_Core_Model_Resource_Url_Rewrite::loadRequestByPath() method:

public function loadByRequestPath(Mage_Core_Model_Url_Rewrite $object, $path)
    // ...
    $select  = $adapter->select()
        ->where('request_path IN (:' . implode(', :', array_flip($pathBind)) . ')')
        ->where('store_id IN(?)', array(Mage_Core_Model_App::ADMIN_STORE_ID, (int)$object->getStoreId()));
    // ...

To accomplish your goal while using most of the native functionality you could rewrite the Mage_Core_Model_Resource_Url_Rewrite::loadRequestByPath() method to check for additional store scopes; as you can see, it currently will only check the current store scope's rewrites as part of the process.

Keep in mind that if you are jumping stores, you also have to handle Magento's hard-coded logic which gives preference to store-setting cookies, so you would likely need to redirect with ?___store=[store code].

  • I think that could be accomplished with setting the store id to 0 for a rewrite? I'll try out redirect with the GET parameter and provide feedback here
    – Chuvisco
    Oct 18, 2013 at 6:49
  • Tried out with the GET parameter. It does work as long as I provide the full product url but it does not work if I want to use the nice urls. Probably because the GET parameter is not removed after the redirect and so the nice urls can't match.
    – Chuvisco
    Oct 18, 2013 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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