Generic url rewrite

Splash Forums PrettyFaces Users Generic url rewrite

This topic contains 14 replies, has 3 voices, and was last updated by  Lincoln Baxter III 9 years, 5 months ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
  • #18663



    Reading many tutorials, i didn’t find any way to make rewrite rules like in php.

    Here is the case, I want to transform any url looking like this

    /faces/user.xhtml?user=6 into this user-6.xhtml, but the rewrite rule has to be the same for another url like:


    To make it clear, i want a generic rule. Pretty Faces can does that?

    Thanks for your help


    Sure, just use something like this:

    <rewrite match="^/(w+)-(d+).xhtml$" substitute="/faces/$1.xhtml?$1=$2" redirect="302" />

    See this chapter of the documentation for details:

    You could also have a look at OcpSoft Rewrite, which is the successor of PrettyFaces:


    With Rewrite you would use a typesafe approach. Something like:

    addRule( Join.path("/{type}-{id}.xhtml").to("/faces/{type}.xhtml?{type}={id}") )



    Does it mean I’d better use Rewrite than PrettyFaces?


    Well, it really depends on what you need. Rewrite lets you do more specific, low-level tasks, where PrettyFaces really serves the purpose of creating Pretty URLs in JSF, and does not have as much power as Rewrite. If you don’t need to enhance the navigation features of JSF, then you might as well use Rewrite, but if any of the other features of PrettyFaces appeal to you, then you should use that.

    Fortunately, in the near future, PrettyFaces will be released using Rewrite as a core, so you won’t have to choose anymore.



    Thanks for your time guys! I will use Pretty Faces, because it fits my only need, but I read some pretty nice stuff about Rewrite, but I will check that later: step by step! ;-)

    By the way,I created a rule, but it screwd the insertion of my css, or something else really weird happened.

    I put this piece of code in my web.xml:

    <filter-name>Pretty Filter</filter-name>
    <filter-name>Pretty Filter</filter-name>

    What is wrong?


    The filter looks good. Could you post the rule you created?

    I’ll always have to make sure that the rules you create don’t match URLs like CSS and images or otherwise those will break.



    Here it is: <rewrite match="/faces/(w+)" substitute="/$1" />


    I think you will have to do it the other way around:

    <rewrite match="/(w+)" substitute="/faces/$1" />

    This will transform requests like /test.xhtml to /faces/test.xhtml.

    But I also think this pattern is a bit to general because /(w+) will also match things like /images.png. Therefore you should use something like:

    <rewrite match="/(w+).xhtml" substitute="/faces/$1.xhtml" />

    I hope this helps. :)


    Glad you got it figured out. If you start to have issues with the RegEx in your rule, then I recommend switching to Rewrite and giving that a shot :)

    Otherwise, you can find more info on regular expressions here if needed (but it seems like you already have a good grasp) –



    I’m using Rewrite because I think I will use some functionnalities in the future.

    I tried that:

    return ConfigurationBuilder.begin()

    Basically I want to remove “faces” in my url (I think you already guest that but who know :-D)


    You can’t use regular expressions directly. You must use parameters, then specify the regex to which each parameter matches.

    As christian showed earlier, use something like this:

    addRule( Join.path("/{page}.xhtml").to("/faces/{page}.xhtml") ).where("page").matches(".*")



    Is it “/{page}.xhtml”).to(“/faces/{page}.xhtml” or “/faces/{page}.xhtml”).to(“/{page}.xhtml”)?


    It’s what I posted.


    Are you running in to issues with it?

Viewing 15 posts - 1 through 15 (of 15 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.