RewriteRule to PrettyFaces.config

Splash Forums PrettyFaces Users RewriteRule to PrettyFaces.config


This topic contains 15 replies, has 3 voices, and was last updated by  mfe_ 8 years, 3 months ago.

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



    I have to convert my current .htaccess entry from

    RewriteRule ^(.*?)\.html index.php?filterrecipename=$1 [PT]

    to the pretty-config.xml.

    I did this:

    But I only get a 404 Error message when accesing for example http://localhost:8080/wie-koche-ich/Spaetzle.html.


    Your pattern is incorrect. Please note that PrettyFaces XML configuration requires a specific format. The documentation describes this here:

    You may find Rewrite to be a simpler configuration method:



    Is there a way to get the compiled or generated regex of,

    <url-mapping id=”viewRecipe”>
    <pattern value=”/{# /(.*?) }” />
    <view-id value=”viewRecipe.jsf” />

    because I’m not able to get it converted.


    First, your pattern is still incorrect. Try the following:

    <url-mapping id=”viewRecipe”>
    <pattern value=”/#{ /(.*?)/ url }” />
    <view-id value=”viewRecipe.jsf” />

    Second, to get the compiled pattern. Look at PrettyContext.getCurrentInstance().getCurrentMapping()



    Thanks for your reply. I’m a little bit confused, because I tried to improve my pattern so that it will work only on characters and with “%20”.
    For example SPAETZLE%20OHNE%20EI.html

    <url-mapping id=”viewRecipe”>
    <pattern value=”/#{ /([a-zA-Z_%0-2]*\.html)/ name }” />
    <view-id value=”/viewRecipe.jsf” />

    But I’m stuck, because I can’t get the pattern with PrettyContext.getCurrentInstance().getCurrentMapping() when I recive a 404 Page ( I only have “Bean Classes”, no “Servlets” or something else.) I checked the pattern at and it seemed to be correct.

    • This reply was modified 8 years, 3 months ago by  mfe_.
    • This reply was modified 8 years, 3 months ago by  mfe_.

    You may need to use \\. instead of \. for the dot character. Could you try this?



    I tried

    <pattern value=”/#{ /([a-zA-Z_%0-2]*\\.html)/ name }” />

    and called http://localhost:8080/wie-koche-ich/SPAETZLE%20OHNE%20EI.html but it results in a 404.

    I removed the “.html” pattern and tried this:

    <pattern value=”/#{ /([a-zA-Z_%0-2]*)/ name }” />

    and called http://localhost:8080/wie-koche-ich/SPAETZLE%20OHNE%20EI and got again a 404 🙁


    Could you try these versions?

    <pattern value=”/#{ /[a-zA-Z_%0-2]+/ name }” />
    <pattern value=”/#{ /[a-zA-Z_%0-2]+\\.html/ name }” />

    And if this still doesn’t work, could you create a minimal Maven project that reproduces this issue?



    Thanks, for your fast reply.

    I think I found the failure in the Regex. When removing the “%20” pattern the regex Rule works.
    Working Regex:

    <pattern value=”/#{ /([a-zA-Z]*\\.html)/ name }” />
    <pattern value=”/#{ /[a-zA-Z]+\\.html/ name }” />

    with: http://localhost:8080/wie-koche-ich/SPAETZLE.html

    So the question is how do I can add the “%20” to allow white spaces in the url.


    Perhaps % has to be escaped? Try:

    <pattern value=”/#{ /([a-zA-Z\\%0-2]*\\.html)/ name }” />

    It is also possible that the regular expression is tested AFTER %20 is decoded. So you could try a simple space in the regex:

    <pattern value=”/#{ /([a-zA-Z ]*\\.html)/ name }” />



    Thanks a lot Christian

    <pattern value=”/#{ /([a-zA-Z ]*\\.html)/ name }” />

    worked for me with http://localhost:8080/wie-koche-ich/SPAETZLE%20OHNE%20EI.html 🙂


    Glad you got it working! You gotta’ love Java’s double escaped Regexes 🙂



    I got something more:

     <url-mapping id="viewIngredient">
            <pattern value="/ingredient/#{ /([a-zA-Z ]*\\.html)/ ingredient }" />
            <view-id value="/viewIngredient.jsf" />

    This regex works fine.
    In my viewIngredient.jsf I have the following viewParameter

                <f:viewParam name="ingredient" value="#{IngredientBean.ingredient}" converter="#{ingredientStringConverter}" required="true" maxlength="150"></f:viewParam>

    Whenever I call http://localhost:8080/wie-koche-ich/ingredient/SPAETZLE%20OHNE%20EI.html my viewParameter ingredient and the converter recives “SPAETZLE OHNE EI.html” as string. So I asked myself if there is a way to tell prettyfaces to assign the parameter without the “.html”?
    In this example the viewParam ingredient should only contain the value “SPAETZLE OHNE EI”.

    If this can be done with prettyfaces this would be really great!

    Best regards

    • This reply was modified 8 years, 3 months ago by  mfe_.

    You could try changing your parameter pattern to the following:

    <pattern value="/ingredient/#{ /([a-zA-Z ]*)/ ingredient }.html" />

    This might work.

    Otherwise, check out – which is the lower-level java-based URL-rewriting framework on which PrettyFaces is built. It will definitely let you do what you need if this does not work 🙂

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

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

Comments are closed.