Basic Examples

Splash Forums Rewrite Users Basic Examples

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

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


    I have setup rewrite which does work now but the documentation does lack a bit of examples on simple used cases.

    For example I would like to forward every request that matches http://mydomain/myapp/html/RESOURCE to http://mydomain/myapp/RESOURCE (simply cut out something). In addition I want to remove all the .jsp extensions inside every path.

    Hope to hear from you – Thanks :)


    Hi There,

    Yes, we really need to work on our documentation for Rewrite – it’s a very new project.

    To do this, you can create a rule like so:


    or you could do it the simpler way:


    To answer your second question, you can do something like this:


    And that should handle just about all the scenarios :), however, note that this is a VERY general rule, and you should be careful that you do not match more than you intended.




    Thanks for the quick response but ReWrite does not work up to now.

    The RewriteFilter starts up successfully on application deployment -> when I hit one of the defined URL patterns like ‘http://mydomain/myapp/html/RESOURCE’ it returns a 404 with no logged output on JBoss AS7 ?

    (using version 1.0.0.Alpha11)


    Is your ConfigurationProvider correctly picked up by Rewrite? You should see a log on the console telling about the providers found. And could you post your rules and which URL you entered that didn’t work correctly?



    I think it does startup correctly:

    10:29:53,450 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) RewriteFilter starting up…

    10:29:53,458 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) Loaded [0] com.ocpsoft.rewrite.servlet.spi.RewriteLifecycleListener []

    10:29:53,465 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) Loaded [1] com.ocpsoft.rewrite.servlet.spi.RequestCycleWrapper [com.ocpsoft.rewrite.servlet.impl.HttpRewriteRequestCycleWrapper<0>]

    10:29:53,472 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) Loaded [1] com.ocpsoft.rewrite.spi.RewriteProvider [com.ocpsoft.rewrite.servlet.impl.DefaultHttpRewriteProvider<0>]

    10:29:53,479 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) Loaded [1] com.ocpsoft.rewrite.servlet.spi.InboundRewriteProducer [com.ocpsoft.rewrite.servlet.impl.HttpInboundRewriteProducer<0>]

    10:29:53,489 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) Loaded [1] com.ocpsoft.rewrite.servlet.spi.OutboundRewriteProducer [com.ocpsoft.rewrite.servlet.impl.HttpOutboundRewriteProducer<0>]

    10:29:53,503 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) Loaded [0] com.ocpsoft.rewrite.servlet.spi.ContextListener []

    10:29:53,518 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) Loaded [0] com.ocpsoft.rewrite.servlet.spi.RequestListener []

    10:29:53,534 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) Loaded [0] com.ocpsoft.rewrite.servlet.spi.RequestParameterProvider []

    10:29:53,548 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) Loaded [0] com.ocpsoft.rewrite.spi.ExpressionLanguageProvider []

    10:29:53,567 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) Loaded [0] com.ocpsoft.rewrite.spi.InvocationResultHandler []

    10:29:53,573 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) Loaded [0] com.ocpsoft.common.spi.ServiceEnricher []

    10:29:53,579 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) Loaded [1] com.ocpsoft.rewrite.config.ConfigurationProvider [com.example.UrlRewriteConfig<10>]

    10:29:53,584 INFO [com.ocpsoft.rewrite.servlet.RewriteFilter] (MSC service thread 1-7) RewriteFilter initialized.

    Here is my config:

    return ConfigurationBuilder.begin() .defineRule().when(Path.matches(“/html/{resource}”)).perform(“/{resource}”))



    And this is not working for you? I’m very surprised. Could you attach your entire application as a ZIP or GZ to this thread? (see attachments below.)


    Your example should work, it’s possible there is something else going on. Did you forget to access your context-path/ ?



    :P sorry my previous post was maybe a bit in confusion

    ReWrite itself is working absolutely correct but the rule which I asked for was simply not what I was thinking of. Because I want when you hit a URL like for example ‘/myapp/test.jsp’ the user should see in his browser ‘/myapp/test’ without the ‘.jsp’ extension. Nevertheless the content which should be served from the server should be still the one from ‘/myapp/test.jsp’ (same with the /html/ inside a URL)

    I explained it wrong by using the word forward with is technically not what I want …

    Is this possible with ReWrite?


    You want to use “withInboundCorrection”




    But .matches(“.*”) returns a JoinParameterBuilder which has no method .withInboundCorrection() ? (that’s a method of Join)


    This should be fixed in latest SNAPSHOT. You’re right – this was broken!



    Now we are closely to what I want :)

    (this example should explain what I wanted to achieve with ‘.withInboundCorrection()’ – I still think this not doing what I want)


    GAH! I see what I did wrong, sorry:

    public class UrlRewriteConfig extends HttpConfigurationProvider

    public int priority()
    return 10;

    public Configuration getConfiguration(final ServletContext context)
    return ConfigurationBuilder
    // hide .jsp extension
    // hide /html/ inside path


    Do you understand why these are changed?

    1. Join.path("/{file}").to("/{file}.jsp")

    2. .where("file").matches("[^/.]+")




    Yes now I got it!

    Thanks a lot for the great support :)

    (after flipping also the second part path (“/{resource}”).to(“/html/{resource}”) everything is perfect)



    :D Sorry but there is just one little thing missing. How can I add exceptions to rules?

    Because I defined in web.xml:





    Which leads to:

    ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host]] (http- Exception Processing ErrorPage[errorCode=404,location=/html/error.jsp]: java.lang.UnsupportedOperationException at …

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

You must be logged in to reply to this topic.

Comments are closed.