uttam
uttam

Reputation: 589

How to create unicode slug for unicode title?

I want to sanitize blog titles with unicode characters in url. I need to replace invalid characters and spaces with "-" for better seo rewriting like this.

        http://example.com/это-моя-хорошая

Can anyone have any idea how to do it?

Upvotes: 1

Views: 1961

Answers (1)

Anthony Faull
Anthony Faull

Reputation: 17957

You can use this algorithm for an SEO-friendly Unicode URL:

  1. Convert the text to Unicode Normalization Form C, i.e. precomposed characters.
  2. Use a regular expression with Unicode character classes to replace each non-letter non-digit character with a space.
  3. Remove leading, trailing and double spaces.
  4. Shorten.
  5. Replace spaces with hyphens.

Upvotes: 3

Related Questions