rewrite problem

7 views
Skip to first unread message

night_stalker

unread,
Sep 8, 2009, 12:12:55 AM9/8/09
to Lift
I want to make RESTful urls (not REST API), for example:

"/post/123" is mapped to "post/show.html" with param "id=123"

but the following rewrite rule seems recursive

LiftRules.rewrite.append {
case RewriteRequest(ParsePath(List("post", id), _, _, _), _, _)
=>
RewriteResponse(List("post","show"), Map("id"->urlDecode(id)))
}

and loops forever ...

Xavi Ramirez

unread,
Sep 8, 2009, 8:56:37 AM9/8/09
to lif...@googlegroups.com
That's because the url "post/show" is being intercepted by the same
rewrite rule that matches "post/<id>" urls. To get around this, try
adding an if statement to your rewrite rule:

LiftRules.rewrite.append {
case RewriteRequest(ParsePath(List("post", id), _, _, _), _, _)
if (id != "show") =>
RewriteResponse(List("post","show"), Map("id"->urlDecode(id)))

Hope this helps!

~Xavi

night_stalker

unread,
Sep 8, 2009, 9:40:18 AM9/8/09
to Lift
Cool, thank you very much!

On Sep 8, 8:56 pm, Xavi Ramirez <xavi....@gmail.com> wrote:
> That's because the url "post/show" is being intercepted by the same
> rewrite rule that matches "post/<id>" urls.  To get around this, try
> adding an if statement to your rewrite rule:
>
> LiftRules.rewrite.append {
>   case RewriteRequest(ParsePath(List("post", id), _, _, _), _, _)
>      if (id != "show") =>
>         RewriteResponse(List("post","show"), Map("id"->urlDecode(id)))
>
> Hope this helps!
>
> ~Xavi
>

David Pollak

unread,
Sep 8, 2009, 11:52:28 AM9/8/09
to lif...@googlegroups.com
On Tue, Sep 8, 2009 at 6:40 AM, night_stalker <usu...@gmail.com> wrote:

Cool, thank you very much!

On Sep 8, 8:56 pm, Xavi Ramirez <xavi....@gmail.com> wrote:
> That's because the url "post/show" is being intercepted by the same
> rewrite rule that matches "post/<id>" urls.  To get around this, try
> adding an if statement to your rewrite rule:
>
> LiftRules.rewrite.append {
>   case RewriteRequest(ParsePath(List("post", id), _, _, _), _, _)
>      if (id != "show") =>
>         RewriteResponse(List("post","show"), Map("id"->urlDecode(id)))

or:
LiftRules.rewrite.append {
     case RewriteRequest(ParsePath(List("post", id), _, _, _), _, _)
=>
       RewriteResponse(List("post","show"), Map("id"->urlDecode(id)), true)
   }

The true parameter stops the rewriting process so you don't get the infinite loop.

 
>
> Hope this helps!
>
> ~Xavi
>
> On Tue, Sep 8, 2009 at 12:12 AM, night_stalker<usur...@gmail.com> wrote:
>
> > I want to make RESTful urls (not REST API), for example:
>
> >  "/post/123" is mapped to "post/show.html" with param "id=123"
>
> > but the following rewrite rule seems recursive
>
> >    LiftRules.rewrite.append {
> >      case RewriteRequest(ParsePath(List("post", id), _, _, _), _, _)
> > =>
> >        RewriteResponse(List("post","show"), Map("id"->urlDecode(id)))
> >    }
>
> > and loops forever ...





--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

night_stalker

unread,
Sep 8, 2009, 12:41:53 PM9/8/09
to Lift
Can't find

RewriteResponse.apply(List[String], Map[String, String], Boolean)

in 1.0 API, is it a new feature?

On Sep 8, 11:52 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> or:
> LiftRules.rewrite.append {
>      case RewriteRequest(ParsePath(List("post", id), _, _, _), _, _)
> =>
>        RewriteResponse(List("post","show"), Map("id"->urlDecode(id)), *true*
> )

David Pollak

unread,
Sep 8, 2009, 12:58:03 PM9/8/09
to lif...@googlegroups.com
On Tue, Sep 8, 2009 at 9:41 AM, night_stalker <usu...@gmail.com> wrote:

Can't find

  RewriteResponse.apply(List[String], Map[String, String], Boolean)

in 1.0 API, is it a new feature?

It's probably a new feature in 1.1 to address the issue that you identified.

I recommend running against 1.1-M4 or SNAPSHOT.
 

On Sep 8, 11:52 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> or:
> LiftRules.rewrite.append {
>      case RewriteRequest(ParsePath(List("post", id), _, _, _), _, _)
> =>
>        RewriteResponse(List("post","show"), Map("id"->urlDecode(id)), *true*
> )
>    }
>
> The true parameter stops the rewriting process so you don't get the infinite
> loop.


Reply all
Reply to author
Forward
0 new messages