Erlang/OTP Forums

Author Message

<  Yaws mailing list  ~  mod_rewrite equivalent for yaws?

Guest
Posted: Sun Nov 05, 2006 5:00 am Reply with quote
Guest
In my quest to convert from Apache to Yaws, one of the things I need
to tackle is figuring out how to replace mod_rewrite with the Yaws
equivalent. I'm certainly willing to learn and adopt the Yaws way of
doing rewrites/redirects, but I need some pointers. The docs are sort
of scarce on this topic, and I haven't been able to find many examples
in the googling and mailing list searching I've done.

At the moment, my rewrites aren't too complex. They tend to look like
this, in Apache:

RewriteRule ^/download.html http://new.site/download/ [L,R=permanent]
RewriteRule ^/list-archives/foo/(.*) http://new.site/thread.php?group=foo [R]
RedirectPermanent /releases/old http://new.site/releases

I did see mention of 'arg_rewrite_mod' in yaws.conf man page, but it's
not clear to me how to utilize this or if this is for something else.

In any case, any hints or pointers would be appreciated.

--
Cheers, L
noss
Posted: Sun Nov 05, 2006 5:10 pm Reply with quote
User Joined: 09 Oct 2005 Posts: 290
On 11/5/06, Count László de Almásy <calmasy@gmail.com> wrote:
> I did see mention of 'arg_rewrite_mod' in yaws.conf man page, but it's
> not clear to me how to utilize this or if this is for something else.

It is supposed to be used for exactly what you want.

As for redirecting you need to rewrite urls to a yaws or appmod that
will redirect the browser.

The feature arg_rewrite_mod is documented, the value assigned to it is
the name of a module that exports a function by the name
'arg_rewrite'/1 that takes an Arg as input and returns a possible
modified Arg.

So you're not limited to regexps, you have erlang code that can parse
complex urls, check values with a db, verify authentication cookies
and so on and then decide what to rewrite the url to.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list

Post recived from mailinglist
View user's profile Send private message
Guest
Posted: Sun Nov 05, 2006 5:20 pm Reply with quote
Guest
On 11/5/06, Christian S <chsu79@gmail.com> wrote:

> As for redirecting you need to rewrite urls to a yaws or appmod that
> will redirect the browser.
>
> The feature arg_rewrite_mod is documented, the value assigned to it is
> the name of a module that exports a function by the name
> 'arg_rewrite'/1 that takes an Arg as input and returns a possible
> modified Arg.
>
> So you're not limited to regexps, you have erlang code that can parse
> complex urls, check values with a db, verify authentication cookies
> and so on and then decide what to rewrite the url to.

Wonderful. So does anyone have an example 'arg_rewrite_mod' module
that illustrates some rewriting that I might be able to modify and
build on? I'm still new to Erlang, so it would be pretty hard to
start from scratch.

--
Cheers, L
Guest
Posted: Sun Nov 05, 2006 5:40 pm Reply with quote
Guest
On 11/5/06, Count L
Guest
Posted: Mon Nov 06, 2006 6:55 am Reply with quote
Guest
On 11/5/06, Christian S <chsu79@gmail.com> wrote:

> As for redirecting you need to rewrite urls to a yaws or appmod that
> will redirect the browser.
>
> The feature arg_rewrite_mod is documented, the value assigned to it is
> the name of a module that exports a function by the name
> 'arg_rewrite'/1 that takes an Arg as input and returns a possible
> modified Arg.

Okay. I've written an arg_rewrite function that does some path
rewrites, like this for example:

arg_rewrite(Arg) ->
Req = Arg#arg.req,
{abs_path, Path} = Req#http_request.path,
NPath = {abs_path, "/new/path"},
Arg#arg{req = Req#http_request{path = NPath}}.

When I load a URL in my browser, the rewrite seems to take effect, and
the /new/path is loaded, but the browser is not redirected there. How
do I redirect to the new path instead of just loading?

I tried adding a line like this to the end of above for testing:

yaws_api:redirect("http://erlang.org").

But that just gives me back an odd error report in the log:

=ERROR REPORT==== 6-Nov-2006::01:41:26 ===
Yaws process died: {badarg,[{yaws_server,handle_request,3},
{yaws_server,aloop,3},
{yaws_server,acceptor0,2},
{proc_lib,init_p,5}]}

--
Cheers, L
noss
Posted: Mon Nov 06, 2006 8:36 am Reply with quote
User Joined: 09 Oct 2005 Posts: 290
On 11/6/06, Count László de Almásy <calmasy@gmail.com> wrote:
> On 11/5/06, Christian S <chsu79@gmail.com> wrote:
> > As for redirecting you need to rewrite urls to a yaws or appmod that
> > will redirect the browser.

> When I load a URL in my browser, the rewrite seems to take effect, and
> the /new/path is loaded, but the browser is not redirected there. How
> do I redirect to the new path instead of just loading?

Rewrite to a page that will perform redirects. You can place
parameters in the bindings.

I too wish arg_rewrite_mod had direct capability to do more than only
rewrite Arg, such as permission denial, redirecting, setting cookies.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list

Post recived from mailinglist
View user's profile Send private message
Guest
Posted: Mon Nov 06, 2006 3:54 pm Reply with quote
Guest
On 11/6/06, Christian S <chsu79@gmail.com> wrote:

> > When I load a URL in my browser, the rewrite seems to take effect, and
> > the /new/path is loaded, but the browser is not redirected there. How
> > do I redirect to the new path instead of just loading?
>
> Rewrite to a page that will perform redirects. You can place
> parameters in the bindings.

You mean like a .yaws page? How would I pass along the new rewritten
Arg to that page? Anyone have an example of doing this?

--
Cheers, L
noss
Posted: Mon Nov 06, 2006 4:25 pm Reply with quote
User Joined: 09 Oct 2005 Posts: 290
On 11/6/06, Count László de Almásy <calmasy@gmail.com> wrote:
> On 11/6/06, Christian S <chsu79@gmail.com> wrote:
> You mean like a .yaws page? How would I pass along the new rewritten
> Arg to that page? Anyone have an example of doing this?

If you have /redirect.yaws, then you can rewrite to
/redirect.yaws/place/to/redirect/to and access the last part through

A#arg.pathinfo
%% Set to 'd/e' when calling c.yaws for the request
%% http://some.host/a/b/c.yaws/d/e

If you have an appmod at /redirect then you can rewrite to
/redirect/other/place and access the last part through

A#arg.appmoddata,
%% the remainder of the path leading up to the query

You can also rewrite A#arg.opaque and push another tuple to the list
with the adress and access A#arg.opaque in your yaws page or appmod.

Opaque = A#arg.opaque,
Newarg = A#arg{opaque=[{redirect, "/redirect destination"}|Opaque])}


Then there is bindings (yaws_api:binding), but I misremembered having
used them for passing information from arg_rewrite_mod to handling
page. They're based on the process dictionary and thus a bit scary to
work with.
(((is there any reason to backend in the process dictionary rather
than adding arg.bindings ?)))


Neither way is suggested in documentation for passing on information.

Having arg_rewrite_mods placing more information in the arg.opaque
field is the cleanest approach under current state of the art (in my
opinion). However, the two first alternatives work well enough for
passing on a string for a redirect page, though.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list

Post recived from mailinglist
View user's profile Send private message
Guest
Posted: Wed Nov 08, 2006 4:02 am Reply with quote
Guest
Thanks allot Christian, this was very helpful!

On 11/6/06, Christian S <chsu79@gmail.com> wrote:
> On 11/6/06, Count L

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum