Reputation: 773
I'm using Magento with multiple stores and store views (1 website, 4 stores with one store view each). I activated the option "add store code to urls" and can access my different stores via http://example.com/storecode/, which works fine. However i have one store code which should be named after two words for SEO purposes. Unfortunately Magento only allows to use an underscore (_) instead of a dash (-) as store code:
The store code may contain only letters (a-z), numbers (0-9) or underscore(_), the first character must be a letter.
As dashes are recommended to separate words in URLs, I'm looking for a method to use a dash as store code. Overriding Magento's validation is no problem, but I'm wondering if there's any special reason dashes are disabled here. Does anybody have an idea?
Thanks, Mathias
Upvotes: 3
Views: 2695
Reputation: 5491
You can always try and make a copy of Mage_Core_Model_Mysql4_Store
in app/code/local
and modify the regular expression to allow the dash. What may be the reason for it is the way Magento interprets _
as dividers or spaces in naming conventions.
I would presume there is a reason, but what that is specifically I'm not sure. If you do make the changes I would recommend doing it on a copy of your codebase/magento before hand to determine if there's any repercussions before doing it on a production site.
protected function _beforeSave(Mage_Core_Model_Abstract $model)
{
if(!preg_match('/^[a-z]+[a-z0-9_\-]*$/',$model->getCode())) {
Mage::throwException(
Mage::helper('core')->__('The store code may contain only letters (a-z), numbers (0-9) or underscore(_), the first character must be a letter'));
}
return $this;
}
Upvotes: 4