Problem with url rewriting

42 views
Skip to first unread message

George A

unread,
May 22, 2012, 8:00:37 AM5/22/12
to UrlRewrite
Hey there,
I'm sorry if the question has already been ansewerd but i couldn't
find an answer as there are so many posts.

My problem is that i have a url like:
localhost:7001/page.jsp?key=home and i want to have the form:
localhost:7001/home

the rules that i'm using are:
<rule>
<from>^paget.jsp?key=([a-z]+)$</from>
<to>$1</to>
</rule>

if the link is <a href="page.jsp?key=<%= Obj.getType() %>">link</a>

and
<outbound-rule>
<from>^paget.jsp?key=([a-z]+)$</from>
<to>$1</to>
</outbound-rule>

if i use response.encodeURL.

In both cases nothing seems to happen as my url remains the same!
Can someone give me a hint of what am i doing wrong?
Thanks in advance!

Wim De Smet

unread,
May 24, 2012, 9:28:25 AM5/24/12
to urlre...@googlegroups.com
Hi George,

On Tue, May 22, 2012 at 2:00 PM, George A <morphe...@gmail.com> wrote:
> Hey there,
> I'm sorry if the question has already been ansewerd but i couldn't
> find an answer as there are so many posts.
>
> My problem is that i have a url like:
> localhost:7001/page.jsp?key=home and i want to have the form:
> localhost:7001/home

The query string is not included in the match by default, so this
won't work. You can use "use-query-string=true" on the top level
element to include it. Usually however, it's better to use a
<condition>, you can use backreferences to what was matched in the
conditions (with %1, %2, ...).

> <outbound-rule>
>         <from>^paget.jsp?key=([a-z]+)$</from>
>        <to>$1</to>
>    </outbound-rule>

You have a misspelling here, not sure if that's the problem. Try
enabling debug logging, I bet the URL you're rewriting is not what you
think it is (in particular, it probably already contains a '/'). It's
good to use anchors here and there, but it means you have to be very
sure you are matching what you think.

regards,
Wim
Reply all
Reply to author
Forward
0 new messages