I am importing categories from external script. All working fine with import.
But with URL KEY Magento is changing value automatically. And I want the url same as I am passing from script.

1) Man_Jeans-1-1  //I am passing from script
2) man-jeans-1-1  //Magento saving like this

1st one is the value that is passed from script like,

$cleanurl = "Man_Jeans-1-1";

But value is automatically changed like 2nd one. Is there anyway I can fix this issue?
I don't want Magento to change the url key.



Urls with Underscores(_) cannot be considered as a valid url because Underscores(_) are not allowed in a host name & other thing is also there that search engines like google are not recognizing those url which contains Underscores(_) with them. For better understanding do refer this

  • Thanks Abhishek for the ans. But we need this anyhow. There is no issue with SEO. – Hardik Feb 15 '18 at 11:49

I don't think this is the cleanest way to do it as it modifies a core file, but if you edit the following file:


Change line 23 from:

$string = preg_replace('#[^0-9a-z]+#i', '-', parent::filter($string));


$string = preg_replace('#[^0-9a-z_]+#i', '-', parent::filter($string));

Then edit and save the category page via the back-end that seems to work.

  • It is indeed not a good approach. But you can implement these changes with a plugin. – Daniel May 29 '19 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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