URLRewriteFilter re-writing of params for a nicer url

232 views Asked by At

I've tried a couple of different options to re-write URLs but I seem to be failing, I'm not sure if it's cause what I'm trying to do is more complex or not...

I have this working currently in my app, calling either of these URLs, I can access my pages:

http://localhost:8080/myapp/template.jsp?site=mysite1&lng=en&pageToLoad=welcome

This could also be (note the m-)

http://localhost:8080/myapp/m-template.jsp?site=mysite1&lng=en&pageToLoad=welcome

However, I would like to re-write my URLs to look like this:

http://localhost:8080/myapp/mysite1/en/welcome
http://localhost:8080/myapp/m/mysite1/en/welcome

I have tried using JBoss's:

org.jboss.web.rewrite.RewriteValve

And now I'm attempting with:

org.tuckey.web.filters.urlrewrite.UrlRewriteFilter

But I can't figure out how my rule in either would need to be written so that I can make this change, any suggestions would be much appreciated.

1

There are 1 answers

0
Nabeel Saad On

Wow, pretty much took all day, but I finally got it. There might be a way to improve, but this is what I got working and I won't be tweaking it myself till it's committed to git :)

<rule>
    <from>^([/m])([a-z]*)/(en|it)/([a-z]*)(?!.)</from>
    <to>/template.jsp?site=$2&amp;lng=$3&amp;pageToLoad=$4</to>
</rule>

<rule>
    <from>m/([a-z]*)/(en|it)/([a-z]*)(?!.)</from>
    <to>/m-template.jsp?site=$1&amp;lng=$2&amp;pageToLoad=$3</to>
</rule>


<outbound-rule>
    <from>([^\r]*)/template\.jsp\?site=([a-z]*)&amp;lng=(en|it)&amp;pageToLoad=([a-z]*)</from>
    <to>%{context-path}/$2/$3/$4</to>
</outbound-rule>

<outbound-rule>
    <from>([^\r]*)/m-template\.jsp\?site=([a-z]*)&amp;lng=(en|it)&amp;pageToLoad=([a-z]*)</from>
    <to>%{context-path}/m/$2/$3/$4</to>
</outbound-rule>

Hope this'll be helpful to others.

Cheers.