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 Tags: , , ,
  1. 20 Grudzień 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 Styczeń 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 Styczeń 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 Styczeń 2013 o 10:31

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

  5. 8 Kwiecień 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 Kwiecień 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 Kwiecień 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 Kwiecień 2013 o 6:36

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

  9. 13 Kwiecień 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 Kwiecień 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 Kwiecień 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 Kwiecień 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 Czerwiec 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 Czerwiec 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 Czerwiec 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 Lipiec 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 Lipiec 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 Sierpień 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 Marzec 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 Kwiecień 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 Kwiecień 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 Czerwiec 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 Lipiec 2014 o 17:10

    Great article.

  33. 5 Sierpień 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 Sierpień 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 Sierpień 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ździernik 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ździernik 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 Kwiecień 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 Lipiec 2015 o 9:16

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

  41. 4 Czerwiec 2016 o 7:16


  42. 19 Czerwiec 2016 o 1:09


  43. 22 Wrzesień 2016 o 11:20


  44. 3 Październik 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 Styczeń 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 Luty 2017 o 2:19


  1. 7 Listopad 2014 o 9:52
  2. 26 Grudzień 2016 o 19:26
  3. 30 Grudzień 2016 o 20:32
  4. 3 Styczeń 2017 o 21:14
  5. 3 Styczeń 2017 o 21:17
  6. 4 Styczeń 2017 o 22:03
  7. 5 Styczeń 2017 o 20:27
  8. 8 Styczeń 2017 o 16:33
  9. 8 Styczeń 2017 o 19:30
  10. 12 Styczeń 2017 o 11:20
  11. 12 Styczeń 2017 o 12:34
  12. 4 Marzec 2017 o 0:05


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


Komentujesz korzystając z konta Log Out / Zmień )

Zdjęcie z Twittera

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

Facebook photo

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

Google+ photo

Komentujesz korzystając z konta Google+. Log Out / Zmień )

Connecting to %s

%d bloggers like this: