Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

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!

share|improve this question
    
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() –  ForMat May 7 at 14:34

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
1  
It should be escaped, because . is everything. If you want the dot \. is the right regex –  Fabian Blechschmidt May 7 at 13:28
    
@FabianBlechschmidt. Thanks for the correction. I changed the answer. –  Marius May 7 at 13:30
    
Using the \. works like a charm, thanks guys!! –  ForMat May 7 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 May 7 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. –  David Manners May 7 at 14:43

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

Refer to Creating Url Rewrites

share|improve this answer
    
I was looking for the answer provided by @Marius. But thanks anyway!! –  ForMat May 7 at 13:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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