we are having a little issue, maybe some smart person knows a fix? We have a few different locales, e.g. NL and UK. A typical product has a different name for both countries, thus a different url_path. Like this: UK -> store.com/uk-productname.html NL -> store.com/nl-productname.html

Now, when you enter the store from another, for example Google URL, like this: NL -> store.com/uk-productname.html This results in a 404 page (and this happens a lot I might add).

We have created a 404 page with a link like this on it:

<a href="?___store=locale_store_nl">

However, this is not foolproof.When you're e.g. already in the right locale but with the wrong locale url_path, you have to click a couple times from 1 locale to the other to get the right product view. Customers lost by then.

How can we make sure these 404 errors do no longer exist. We have a .nl domainname as well, but we wanted to keep everything in the .com version this time. In the .nl domain we have an htaccess file that does this, but that only helps when WE put the link somewhere. Anybody sharing or pasting the link they then see elsewhere, will send their visitors to the 404 because of the default locale of the UK version.

RewriteRule ^(.*)$  http://www.store.com/$1?___store=locale_store_nl [QSA,L]

A 404 extension that just catches all 404s doesn't work, because this creates a loop somehow. We need something that knows the NL product url_path belongs to the NL locale, and not go to a 404 when entered through the UK locale.

I hope this made sense.

Who went through this before?

Thanks a lot.

ps. We have already setup a few links by hand in the URL rewrite management section by pointing to the exact product path, but once we clear our tables (have to because magento keeps increasing this table to enourmous sizes) those are gone again. Plus that is not the way to go IMO.

  • I am just curious: are you using Enterprise or CE. reason I ask, is that that placing __store to any URL bypasses EE FPC...which could be a performance issue, as your entire nl store would not use FPC, due to the rewrite rule. ref: app/code/core/Enterprise/PageCache/Model/Processor/Default.php
    – ProxiBlue
    Feb 24, 2016 at 3:44
  • Is the url pattern for your product urls ALWAYS: uk- and nl- for those urls?
    – ProxiBlue
    Feb 24, 2016 at 3:46
  • @ProxiBlue: That would be CE 1.9.2. And No, that prefix was for clarification only.
    – Kim K.
    Feb 24, 2016 at 8:59

1 Answer 1


This assumes all your url's are on the given pattern of

UK- for uk , NL- for nl

Sorry, no time for full code solution, but it should be pretty straight forward.

Listen to the event controller_action_predispatch_cms_index_noRoute In that observed event code, do the following actions.

  1. Test of the given uri has the pattern of XX-XXXXXXX - basically to determine if this is a url of a product that went 404, or something else. - up to you to decide how to do the pattern matching, and what patterns are suitable to trap ;) - If not matching the pattern, continue with the 404, as normal. (simply exit observer)

you can get the request URI like this:

$event = $observer->getEvent();
$controllerAction = $event->getControllerAction();
$request = $controllerAction->getRequest();
$requestUri = $request->getRequestUri();
  1. Get the current store locale: Mage::app()->getStore()->getLocaleCode();
  2. test if the current local code and the locale code in the uri is the same - if they are - this is a valid 404, and exit.
  3. replace the locale in the uri with the current locale code

you should now have the requested uri, but substituted the locale to the (correct?) current locale.

  1. Proceed with a load of the adjusted uri, cancelling the current request

$controllerAction->getResponse()->setRedirect($updatedUrl); $controllerAction->setFlag('', 'no-dispatch', true);

All this is untested, and off-the-top-of-my-head as a potential idea how to solve this.

Hope it helps in some way.

  • Thanks, but this won't work due to not having the prefix. I think we best just setup the stores to go to their own corresponding country extension like we usually do. We just liked to do it different once, unfortunately it is not flexible like that. You'd assume Magento would/could just look at to what storeview the url_path belongs and send forward like that. Easy does it (but after 8 years, it is safe to say Magento doesn't like easy ;-)).
    – Kim K.
    Feb 24, 2016 at 9:04

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.