i have option “Store Code to Urls” turned on (admin -> system -> configuration -> web -> url options).
Problem is that if i access my homepage without store code, it works. I mean both examples works:
http://example.com/
http://example.com/code/
But first url (without store code) should redirect to url with store code. I’ve tried to put rewrite rules in htaccess but without success, i’ve tried planty of possibilities.
Magento build in rewrites rules doesnt seem to be helpfull – i’ve tried rewrite “/” to “code”, but it result with “/code/code” url suffix.
The reason for this behavior can be found in
Mage_Core_Model_Url_Rewrite::rewrite. There is no redirect for base URLs without store code.Below is a pretty ugly solution, but it should work in your case. It will redirect to the base URL including store code as long as current store code is not found in the request URI:
app/code/local/Danslo/RedirectToStore/Model/Observer.php:
app/code/local/Danslo/RedirectToStore/etc/config.xml:
app/etc/modules/Danslo_RedirectToStore.xml: