4

I wonder if it is possible to use a DOT (.) in a product URL in Magento. I want to create a product URL that looks something like this:

http://www.domain.com/galaxy-tab4-10.1.html

But when I try to do this then after saving the product the DOT in 10.1 is automatically changed in a DASH (-) and the URL becomes:

http://www.domain.com/galaxy-tab4-10-1.html

I have seen other websites that have DOTs in the path part of their URLs. I'm not sure why Magento doesn't accept them.

Any thoughts are welcome!

1
  • For anyone: To use DOTs in category URLs I used the same solution provided by @Marius below, and applied it to the method Mage_Catalog_Model_Category::formatUrlKey()
    – MatthijsIJ
    Commented May 7, 2014 at 14:34

2 Answers 2

5

You need to rewrite this method: Mage_Catalog_Model_Product_Url::formatUrlKey().
You need to change this line:

$urlKey = preg_replace('#[^0-9a-z]+#i', '-', Mage::helper('catalog/product_url')->format($str));

What this basically means is, 'replace anything that's not alphanumeric with -'.
You need to make it allow dots also. Just add a dot in the regular expression. #[^0-9a-z\.]+#i
(not sure if it should be escaped \. - test them both).
Seams like it should be escaped.
Thanks @FabianBlechschmidt for the crash course in regex.

6
  • 2
    It should be escaped, because . is everything. If you want the dot \. is the right regex Commented May 7, 2014 at 13:28
  • @FabianBlechschmidt. Thanks for the correction. I changed the answer.
    – Marius
    Commented May 7, 2014 at 13:30
  • Using the \. works like a charm, thanks guys!!
    – MatthijsIJ
    Commented May 7, 2014 at 13:45
  • There was an edit suggestion on the answer proposed by an anonymous user that I rejected because it seamed to change a lot of of the answer. It may be useful because I'm lousy at regex. This was it. "(. does not need escaping inside a character class. It only has meaning outside of [])"
    – Marius
    Commented May 7, 2014 at 14:40
  • The edit seems to be correct. Note tested with code but I did put the regex into regexr.com and it appears to match either way. Commented May 7, 2014 at 14:43
0

Not Sure if this fulfill your requirement, Magento has feature to manage url for products

Refer to Creating Url Rewrites

1
  • I was looking for the answer provided by @Marius. But thanks anyway!!
    – MatthijsIJ
    Commented May 7, 2014 at 13:49

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.