0

I am working on a ASP.NET MVC app. This app displays a detail information regarding a product.

The product name can have any special chars like single quote, the percentage symbol, the Registered symbol the one with a circle and 'R' inside, the Trademark symbol etc.

Currently all these are replaced with a '-'. If the name is like this:

Super - Men's 100% Polyester Knit Shirts

It appears like this in the URL:

8080/super---men-s-100-polyester-knit-shirts/maverick
 - men-s-100-polyester-knit-shirts

This is done in Js like so:

Name.replace(/([~!@#$%^&*()_+=`{}\[\]\|\\:;'"<>,.\/? ])+/g, '-').replace(/^(-)+|(-)+$/g, '');

So the question is, should the name be displayed as-is in the URL? If yes, some pointers please. If no, please provide some valid reasons like standards as followed today that will help me put the point across the table.

Regards.

Codehelp
  • 4,157
  • 9
  • 59
  • 96

1 Answers1

0

The short answer is not to fiddle with it. It's as good as it gets out of the box.

The Url can only contain a small number of alphanumeric letters. which basically means you can only have 0-9 a-z and - _ . ~.

All other characters need to be encoded. Now that you can have arabic url's too it has gotten a little more complicated.

But assuming your website is indo-european this is it. So you will never be able to have full product names in your url.

And renaming them as something more cool like replacing % with "percent" in the url can bring desaster upon your url's as in some cases the "fake" names may not end up unique and therefore end up with unreliable routing.

look at URI characters on wiki

Archlight
  • 2,019
  • 2
  • 21
  • 34