Strona główna > Java > java seo friendly url (slug)

java seo friendly url (slug)

Tworząc aplikację internetową, często w adresach pojawia się jakiś tekst, np tytuł wprowadzony przez użytkownika podczas dodawania artykuły, chociażby blogi na wordpressie.
Jednak adres w postaciśmieszny-artykuł podobno jest gorzej odbierany przez google, dwa w niektórych przeglądarkach jest on niezbyt czytelny bo przeglądarka nie potrafi przetworzyć np.: IE.
Dlatego tekst wprowadzony przez użytkownika należy nieco zmodyfikować. Z racji ze potrzebuję takiej funkcji napisałem sobie odpowiednią klasę:

import java.text.Normalizer;
import java.text.Normalizer.Form;

public class Slug {

    public static String parse(String input) {
        if (isEmptyOrNull(input)) {
            return "";
        String out = normalize(input);
        out = removeDuplicateWhiteSpaces(out);
        out = out.toLowerCase();
        out = out.replace(" ", "-");

        return out;

    private static String normalize(String input) {
        String result = Normalizer.normalize(input, Form.NFD).replaceAll("[^\\p{ASCII}]", ""); // 1
        result = result.replaceAll("[^a-zA-Z0-9\\s]", " "); // 2

        return result;

    private static String removeDuplicateWhiteSpaces(String input) {
        return input.replaceAll("\\s+", " ");

    private static boolean isEmptyOrNull(String input) {
        return (input == null || input.trim().length() == 0);

1) tekst jest normalizowany, tzn znaki diakrytyczne są zmieniane na znaki ASCII
2) tutaj zmieniamy wszystkie znaki niealfanumeryczne na spacje

Możemy przetestować klasę:

        String inputText = "123-test       nąśŹA       zima 🙂 !! #@ zła";

wynik: 123-test-nasza-zima-za – zjadło literkę „l”
okazuje się że na l może być zamieniony a nie ł
Niestety w sieci nie widzę żadnej wskazówki jak ładnie rozwiązać ten problem, więc na razie pozostaje mi tylko zmodyfikować ciało funkcji normalize:

        String result = input.replace("ł", "l").replace("Ł", "L");

        result = Normalizer.normalize(result, Form.NFD).replaceAll("[^\\p{ASCII}]", ""); // 1
        result = result.replaceAll("[^a-zA-Z0-9\\s]", " "); // 2

jeśli ktoś wie jak to zrobić normalnie a nie poprzez takie kombinacje, będę wdzięczny za komentarz

Kategorie:Java Tagi: , , ,
  1. 20 grudnia 2012 o 16:52

    Howdy I am so glad I found your blog, I really found you by accident, while I was looking on Askjeeve for something else,
    Anyways I am here now and would just like to say thanks a lot for a
    tremendous post and a all round enjoyable blog (I also love the theme/design), I don’t have time to browse it all at the moment but I have book-marked it and also added your RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the fantastic job.

  2. 6 stycznia 2013 o 7:28

    This is a topic that is close to my heart… Best wishes! Exactly where are
    your contact details though?

  3. 14 stycznia 2013 o 21:49

    Hey there, You’ve done a fantastic job. I’ll definitely digg it
    and personally suggest to my friends. I’m sure they’ll be benefited from this site.

  4. 29 stycznia 2013 o 10:31

    Marvelous, what a blog it is! This website presents helpful
    information to us, keep it up.

  5. 8 kwietnia 2013 o 18:44

    I have fun with, lead to I discovered just what I was taking a look for.
    You’ve ended my 4 day long hunt! God Bless you man. Have a nice day. Bye

  6. seo
    10 kwietnia 2013 o 8:22

    What i do not understood is actually how you are now not actually much
    more well-liked than you may be right now. You are so intelligent.
    You realize therefore significantly on the subject
    of this topic, produced me individually believe it from numerous varied angles.

    Its like men and women are not interested unless it is something to do with Lady gaga!
    Your own stuffs outstanding. Always handle it up!

  7. 11 kwietnia 2013 o 3:05

    Write more, thats all I have to say. Literally, it seems as
    though you relied on the video to make your point.
    You definitely know what youre talking about, why waste your
    intelligence on just posting videos to your blog when you could be giving us
    something enlightening to read?

  8. 13 kwietnia 2013 o 6:36

    I love it when folks come together and share ideas. Great site, keep
    it up!

  9. 13 kwietnia 2013 o 20:22

    I really love your website.. Pleasant colors & theme. Did you
    make this website yourself? Please reply back as I’m hoping to create my own website and want to know where you got this from or what the theme is named. Thanks!

  10. 13 kwietnia 2013 o 20:41

    I pay a visit each day a few blogs and blogs to read content, except
    this webpage presents quality based writing.

  11. 14 kwietnia 2013 o 3:23

    We stumbled over here from a different website and thought I should check things out.
    I like what I see so now i am following you. Look forward to
    checking out your web page again.

  12. 21 kwietnia 2013 o 4:26

    This is a topic which is near to my heart… Best wishes!
    Where are your contact details though?

  13. 21 Maj 2013 o 7:35

    Great beat ! I would like to apprentice whilst you amend your web site, how can i subscribe for a blog website?

    The account helped me a acceptable deal. I were a little bit familiar
    of this your broadcast offered bright clear idea

  14. 2 czerwca 2013 o 2:10

    The clownfish are hermaphrodites, which means they develop into males
    first, and when they mature, they tend to change as females.
    There should be live rock and sand inside the tank. The less
    intense light they have, such as a fluorescent light, the less amount of algae will grow on the glass and decorations.

  15. 6 czerwca 2013 o 22:41

    Brainpulse is a top SEO Company India, which ensures
    that the search engine rankings of the web page fall within the top 10.
    Look for a company that makes a certain amount of effort in knowing your business, what you wish to achieve from your web presence etc.
    This has said to be effective in reducing paper
    waste by 90%.

  16. 30 czerwca 2013 o 14:54

    howdy! , I like the creating hence a whole lot! discuss most people talk more about this page in America online? I would like a professional within this area to uncover this challenge. Maybe which is anyone! Eager for help you.

  17. 9 lipca 2013 o 23:59

    What’s up everyone, it’s my first pay a quick visit at this site,
    and piece of writing is in fact fruitful designed for me, keep up posting these content.

  18. 21 lipca 2013 o 16:50

    People go for crash dieting is bad in order to function
    normally. As for trends in Dieting Is Bad, it’s hard to know what’s truly changing here.
    This is TRUE because the body is sent into starvation mode because it thinks
    it’s in a period of time. Before, I used Spark People, which is said to prolong health, stave off diagnosis, and it would be almost impossible to drop out.

  19. 12 sierpnia 2013 o 3:03

    Woah! I’m really enjoying the template/theme of this site. It’s
    simple, yet effective. A lot of times it’s challenging to get that „perfect balance” between user friendliness and visual appeal. I must say you’ve
    done a superb job with this. Additionally, the blog loads super fast for me on Internet explorer.
    Excellent Blog!

  20. 28 marca 2014 o 22:10

    Hi! This post could not be written any better! Reading through this post reminds me of my previous room
    mate! He always kept talking about this. I will forward
    this page to him. Pretty sure he will have a good read. Thanks for

  21. 14 kwietnia 2014 o 17:53

    A person essentially assist to make critically
    articles I might state. That is the very first time I frequented your web
    page and up to now? I surprised with the analysis you made to make
    this actual put up amazing. Great process!

  22. 23 kwietnia 2014 o 18:32

    Hi there, after reading this amazing piece of writing i am
    too happy to share my knowledge here with friends.

  23. 18 Maj 2014 o 4:53

    If you elect to download iPhone flick you’ll need MP4 codec.
    You can jailbreak iOS 4.0.2 via Redsn0w and 4.0.1 can be jailbroken via jailbreakme 2.0.

    Generally there is more than one strategy to jailbreak.

  24. 20 Maj 2014 o 5:06

    Some could be presented as presents out of your large neighbors.
    Cultural Location on Facebook is just a simple
    online game much like Simcity. But it is only recommended by me for adventurous and the courageous.

  25. 24 Maj 2014 o 22:29

    For more farming fun: click the link a subscription to my posts.
    Both Cash Puppies come with a few rules that don’t connect with
    their Plantation Cash competitors. Let’s possess a glance at the things they are.

  26. 27 Maj 2014 o 5:22

    Just stated repositories are sources or spots where you could download software
    applications. Is your iPhone Mobile 4 caught with the
    spinning wheel to the Apple logo?

  27. 30 Maj 2014 o 0:34

    This game is a must for Boggle or Scrabble lovers. Enabling this feature will permit you
    to instantly reply with out quitting the existing page.
    You can easily find it in iTunes Application Store.

  28. 30 Maj 2014 o 7:17

    These games could teach them anything or two, even though
    they don’t understand it. Make sure most of the routes are very different however the treasure in the long run is the

  29. 30 Maj 2014 o 16:18

    One of the tools therefore mentioned is the jailbreak application that was lamera1n. You could add (or remove) repos within Cydia.
    This series of city places would be the campaign’s beginning.

  30. 31 Maj 2014 o 8:17

    Within this criticism we suppose that you pull straight from lifestyle or from the suitable
    image. Do not overlook, the arabesque includes the whole
    of the top such as the hair.

  31. 10 czerwca 2014 o 14:42

    Hello there! This is my first comment here so I just wanted to give
    a quick shout out and say I genuinely enjoy reading through your
    articles. Can you suggest any other blogs/websites/forums that
    cover the same topics? Thanks for your time!

  32. 30 lipca 2014 o 17:10

    Great article.

  33. 5 sierpnia 2014 o 17:14

    Nice post. I learn something totally new and challenging on websites
    I stumbleupon everyday. It will always be helpful to read through content from other authors and practice something from their sites.

  34. 6 sierpnia 2014 o 10:56

    Toller Post. Genau so unterhaltsam, wie das Gaming auch.
    So verrissen Computerspiele auch hingestellt wird, so ist psychologisch bewiesen worden, dass Gaming, ein dem Alter des
    Gamers angemessenes Game vorausgesetzt, förderlich
    für das Reaktionsvermögen ist. Beim Spielen lernt der Gamer
    fernab vom Alltag in erhöhter Frequenz zu Reagieren und zwischen wichtig und unwichtig zu unterscheiden. Viele
    Spiele vermitteln zusätzlich noch Kenntnisse über Wirtschaftlichkeit und fördern die Logik.
    Auch die verpönten MMOs können doch häufig den vorgeworfenen Effekt
    des Abdriftens in eine virtuelle Realität} aufhalten. Der Spieler mag mitunter vielen Freaks begegnen, jedoch findet der Spieler häufig in seinem Lieblingsspiel Gleichgesinnte.

    Kurz gehalten: das Gaming ist das Beste überhaupt!
    Ungeachtet des Games und der Plattform, Spielen ist ein Kulturgut.

  35. 10 sierpnia 2014 o 17:30

    Light this time is reflected on inclusions positioned parallel with
    each other. The shapes of designs also have meanings and
    symbolism such as the elephant with wealth and luck.
    Chrysoberyl This gemstone is arguably the most popular gemstone for its cats
    eye inclusions.

  36. 17 października 2014 o 18:20

    When someone writes an article he/she maintains
    the idea of a user in his/her mind that how a user can be aware
    of it. Thus that’s why this post is perfect.

  37. 22 października 2014 o 16:59

    Nowadays the SEO industry gets a bad reputation from the amount of snake oil salesmen and overseas companies currently set
    Bookmarked your blog, heres to hoping you keep up to date with regular posts

  38. 2 kwietnia 2015 o 16:18

    Excellent beat ! I would like to apprentice at the
    same time as you amend your web site, how can i subscribe for a
    blog site? The account aided me a applicable deal. I had been a
    little bit familiar of this your broadcast offered shiny clear concept

  39. 4 Maj 2015 o 23:23

    It’s actually a nice and useful piece of info. I’m satisfied that you just shared this useful info with us.

    Please keep us up to date like this. Thanks for sharing.

  40. 3 lipca 2015 o 9:16

    Yes! Finally someon writes aƄoսt tethered jealbreak.

  41. 4 czerwca 2016 o 7:16


  42. 19 czerwca 2016 o 1:09


  43. 22 września 2016 o 11:20


  44. 3 października 2016 o 5:29

    Is there a benefit in employing someone with experience to carry out the link exchanges, or
    do you do it yourself?
    Will surely be coming back, ’tis a great site!

  45. 15 stycznia 2017 o 3:19

    Today, I went to the beachfront with my kids.

    I found a sea shell and gave it to my 4 year old daughter and said „You can hear the ocean if you put this to your ear.” She put the shell to her ear
    and screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is entirely off
    topic but I had to tell someone!

  46. 10 lutego 2017 o 2:19


  47. 1 Maj 2017 o 7:11

    Its not my first time to pay a quick visit this web page, i am visiting this website dailly and obtain good data from here everyday.

  48. 14 Maj 2017 o 19:33

    What’s up to every body, it’s my first pay a quick visit of
    this webpage; this web site contains amazing and in fact good data in support of visitors.

  49. 2 czerwca 2017 o 5:50

    Very good post. I definitely love this website.
    Stick with it!

  50. 19 lipca 2017 o 21:59

    Magnificent website. A lot of helpful information here.
    I’m sending it to several buddies ans additionally sharing in delicious.
    And obviously, thanks in your effort!

  51. 8 września 2017 o 5:31

    My brother suggested I would possibly like this website.

    He was once totally right. This publish actually made my
    day. You cann’t consider simply how so much time I had spent for this info!
    Thank you!

  52. 21 września 2017 o 23:23

    Attractive section of content. I simply stumbled upon your web site and in accession capital to claim that I acquire in fact enjoyed account your blog posts.
    Anyway I’ll be subscribing for your augment or even I fulfillment you get entry to consistently quickly.

  53. 28 września 2017 o 6:20

    It’s going to be finish of mine day, except before finish I am reading this fantastic paragraph to improve my know-how.

  54. 14 października 2017 o 4:20

    Great info. Lucky me I came across your website by accident (stumbleupon).
    I’ve bookmarked it for later!

  55. 13 stycznia 2018 o 22:59

    When I originally commented I appear to have clicked on the -Notify
    me when new comments are added- checkbox and from now on each time a
    comment is added I receive four emails with the same comment.

    There has to be a way you are able to remove me from
    that service? Cheers!

  56. 7 lutego 2018 o 0:04

    Great web site. A lot of useful information here.

    I’m sending it to some friends ans additionally sharing in delicious.
    And certainly, thank you to your sweat!

  57. 24 marca 2018 o 10:26

    If you are going for finest contents like I do, only pay
    a visit this web site all the time because it offers feature contents, thanks

  58. 11 sierpnia 2018 o 5:12


  59. dog
    1 stycznia 2019 o 11:49

    I’ve been exploring for a little bit for any high quality articles or blog posts
    on this sort of space . Exploring in Yahoo I eventually stumbled upon this web site.

    Studying this info So i’m happy to express that I have an incredibly
    good uncanny feeling I found out exactly what I needed. I such a lot indisputably will make sure to
    don?t fail to remember this web site and give it a glance on a relentless basis.

  60. 20 września 2019 o 16:49

    If you adore to play a variety of various poker games then find a place
    that has a variety of poker video games to offer.
    Online poker is about playing when you are in a
    comfortable situation. To win at online poker you must play
    restricted in loose video games and play in free games
    only. The reward is only 1 of several accessible bonus offers.
    Initial, you can easily know the typical chip stack.

  61. 25 września 2019 o 0:05

    Hello, all is going sound here and ofcourse every one
    is sharing facts, that’s in fact fine, keep up writing.

  62. 25 września 2019 o 4:10

    Aw, this was an extremely good post. Taking a few minutes and actual effort to create a top notch article…
    but what can I say… I procrastinate a whole lot and don’t manage to
    get nearly anything done.

  63. 27 września 2019 o 16:07

    Unquestionably believe that which you stated.
    Your favorite justification appeared to be on the web the simplest thing to be aware
    of. I say to you, I definitely get annoyed while people consider worries that they just don’t know about.
    You managed to hit the nail upon the top as well as defined out the whole thing without having side effect
    , people can take a signal. Will likely be back to get more.

  1. 7 listopada 2014 o 9:52
  2. 26 grudnia 2016 o 19:26
  3. 30 grudnia 2016 o 20:32
  4. 3 stycznia 2017 o 21:14
  5. 3 stycznia 2017 o 21:17
  6. 4 stycznia 2017 o 22:03
  7. 5 stycznia 2017 o 20:27
  8. 8 stycznia 2017 o 16:33
  9. 8 stycznia 2017 o 19:30
  10. 12 stycznia 2017 o 11:20
  11. 12 stycznia 2017 o 12:34
  12. 4 marca 2017 o 0:05
  13. 11 czerwca 2017 o 8:44
  14. 16 lipca 2017 o 12:20


Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:


Komentujesz korzystając z konta Wyloguj /  Zmień )

Zdjęcie na Google

Komentujesz korzystając z konta Google. Wyloguj /  Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Wyloguj /  Zmień )

Zdjęcie na Facebooku

Komentujesz korzystając z konta Facebook. Wyloguj /  Zmień )

Połączenie z %s

%d blogerów lubi to: