From: <ca...@gm...> - 2006-11-05 05:00:13
|
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=3Dpermanent] RewriteRule ^/list-archives/foo/(.*) http://new.site/thread.php?group=3Dfoo= [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. --=20 Cheers, L=E1szl=F3 |
From: Christian S <ch...@gm...> - 2006-11-05 17:10:10
|
T24gMTEvNS8wNiwgQ291bnQgTMOhc3psw7MgZGUgQWxtw6FzeSA8Y2FsbWFzeUBnbWFpbC5jb20+ IHdyb3RlOgo+IEkgZGlkIHNlZSBtZW50aW9uIG9mICdhcmdfcmV3cml0ZV9tb2QnIGluIHlhd3Mu Y29uZiBtYW4gcGFnZSwgYnV0IGl0J3MKPiBub3QgY2xlYXIgdG8gbWUgaG93IHRvIHV0aWxpemUg dGhpcyBvciBpZiB0aGlzIGlzIGZvciBzb21ldGhpbmcgZWxzZS4KCkl0IGlzIHN1cHBvc2VkIHRv IGJlIHVzZWQgZm9yIGV4YWN0bHkgd2hhdCB5b3Ugd2FudC4KCkFzIGZvciByZWRpcmVjdGluZyB5 b3UgbmVlZCB0byByZXdyaXRlIHVybHMgdG8gYSB5YXdzIG9yIGFwcG1vZCB0aGF0CndpbGwgcmVk aXJlY3QgdGhlIGJyb3dzZXIuCgpUaGUgZmVhdHVyZSBhcmdfcmV3cml0ZV9tb2QgaXMgZG9jdW1l bnRlZCwgdGhlIHZhbHVlIGFzc2lnbmVkIHRvIGl0IGlzCnRoZSBuYW1lIG9mIGEgbW9kdWxlIHRo YXQgZXhwb3J0cyBhIGZ1bmN0aW9uIGJ5IHRoZSBuYW1lCidhcmdfcmV3cml0ZScvMSB0aGF0IHRh a2VzIGFuIEFyZyBhcyBpbnB1dCBhbmQgcmV0dXJucyBhIHBvc3NpYmxlCm1vZGlmaWVkIEFyZy4K ClNvIHlvdSdyZSBub3QgbGltaXRlZCB0byByZWdleHBzLCB5b3UgaGF2ZSBlcmxhbmcgY29kZSB0 aGF0IGNhbiBwYXJzZQpjb21wbGV4IHVybHMsIGNoZWNrIHZhbHVlcyB3aXRoIGEgZGIsIHZlcmlm eSBhdXRoZW50aWNhdGlvbiBjb29raWVzCmFuZCBzbyBvbiBhbmQgdGhlbiBkZWNpZGUgd2hhdCB0 byByZXdyaXRlIHRoZSB1cmwgdG8uCg== |
From: <ca...@gm...> - 2006-11-05 17:19:54
|
On 11/5/06, Christian S <ch...@gm...> 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. --=20 Cheers, L=E1szl=F3 |
From: Jeroen \Slim\ v. G. <as...@gm...> - 2006-11-05 17:40:02
|
On 11/5/06, Count L=E1szl=F3 de Alm=E1sy <ca...@gm...> wrote: > 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. arg_rewrite(Arg) -> Req =3D Arg#arg.req, _Meth =3D Req#http_request.method, {abs_path, Path} =3D Req#http_request.path, % error_logger:info_msg("Path:~p,Req:~p,Meth:~p~n",[Path,Req,Meth]), case list_to_binary(Path) of <<"/buttons/", _Rest/binary>> -> Arg; <<"/css/", _Rest/binary>> -> Arg; _ -> NPath =3D {abs_path, [$/|atom_to_list(?MODULE)]++Path}, %error_logger:info_msg("New path ~p~n",[NPath]), Arg#arg{req =3D Req#http_request{path =3D NPath}} end. --=20 Jeroen "Slim" van Gelderen - +1 242 646 8656 |
From: <ca...@gm...> - 2006-11-06 06:54:57
|
On 11/5/06, Christian S <ch...@gm...> 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 =3D Arg#arg.req, {abs_path, Path} =3D Req#http_request.path, NPath =3D {abs_path, "/new/path"}, Arg#arg{req =3D Req#http_request{path =3D 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: =3DERROR REPORT=3D=3D=3D=3D 6-Nov-2006::01:41:26 =3D=3D=3D Yaws process died: {badarg,[{yaws_server,handle_request,3}, {yaws_server,aloop,3}, {yaws_server,acceptor0,2}, {proc_lib,init_p,5}]} --=20 Cheers, L=E1szl=F3 |
From: Christian S <ch...@gm...> - 2006-11-06 08:36:07
|
T24gMTEvNi8wNiwgQ291bnQgTMOhc3psw7MgZGUgQWxtw6FzeSA8Y2FsbWFzeUBnbWFpbC5jb20+ IHdyb3RlOgo+IE9uIDExLzUvMDYsIENocmlzdGlhbiBTIDxjaHN1NzlAZ21haWwuY29tPiB3cm90 ZToKPiA+IEFzIGZvciByZWRpcmVjdGluZyB5b3UgbmVlZCB0byByZXdyaXRlIHVybHMgdG8gYSB5 YXdzIG9yIGFwcG1vZCB0aGF0Cj4gPiB3aWxsIHJlZGlyZWN0IHRoZSBicm93c2VyLgoKPiBXaGVu IEkgbG9hZCBhIFVSTCBpbiBteSBicm93c2VyLCB0aGUgcmV3cml0ZSBzZWVtcyB0byB0YWtlIGVm ZmVjdCwgYW5kCj4gdGhlIC9uZXcvcGF0aCBpcyBsb2FkZWQsIGJ1dCB0aGUgYnJvd3NlciBpcyBu b3QgcmVkaXJlY3RlZCB0aGVyZS4gIEhvdwo+IGRvIEkgcmVkaXJlY3QgdG8gdGhlIG5ldyBwYXRo IGluc3RlYWQgb2YganVzdCBsb2FkaW5nPwoKUmV3cml0ZSB0byBhIHBhZ2UgdGhhdCB3aWxsIHBl cmZvcm0gcmVkaXJlY3RzLiBZb3UgY2FuIHBsYWNlCnBhcmFtZXRlcnMgaW4gdGhlIGJpbmRpbmdz LgoKSSB0b28gd2lzaCBhcmdfcmV3cml0ZV9tb2QgaGFkIGRpcmVjdCBjYXBhYmlsaXR5IHRvIGRv IG1vcmUgdGhhbiBvbmx5CnJld3JpdGUgQXJnLCBzdWNoIGFzIHBlcm1pc3Npb24gZGVuaWFsLCBy ZWRpcmVjdGluZywgc2V0dGluZyBjb29raWVzLgo= |
From: <ca...@gm...> - 2006-11-06 15:53:44
|
On 11/6/06, Christian S <ch...@gm...> 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? --=20 Cheers, L=E1szl=F3 |
From: Christian S <ch...@gm...> - 2006-11-06 16:25:07
|
T24gMTEvNi8wNiwgQ291bnQgTMOhc3psw7MgZGUgQWxtw6FzeSA8Y2FsbWFzeUBnbWFpbC5jb20+ IHdyb3RlOgo+IE9uIDExLzYvMDYsIENocmlzdGlhbiBTIDxjaHN1NzlAZ21haWwuY29tPiB3cm90 ZToKPiBZb3UgbWVhbiBsaWtlIGEgLnlhd3MgcGFnZT8gIEhvdyB3b3VsZCBJIHBhc3MgYWxvbmcg dGhl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aGF2aW5nCnVzZWQg dGhlbSBmb3IgcGFzc2luZyBpbmZvcm1hdGlvbiBmcm9tIGFyZ19yZXdyaXRlX21vZCB0byBoYW5k bGluZwpwYWdlLiBUaGV5J3JlIGJhc2VkIG9uIHRoZSBwcm9jZXNzIGRpY3Rpb25hcnkgYW5kIHRo dXMgYSBiaXQgc2NhcnkgdG8Kd29yayB3aXRoLgooKChpcyB0aGVyZSBhbnkgcmVhc29uIHRvIGJh Y2tlbmQgaW4gdGhlIHByb2Nlc3MgZGljdGlvbmFyeSByYXRoZXIKdGhhbiBhZGRpbmcgYXJnLmJp bmRpbmdzID8pKSkKCgpOZWl0aGVyIHdheSBpcyBzdWdnZXN0ZWQgaW4gZG9jdW1lbnRhdGlvbiBm b3IgcGFzc2luZyBvbiBpbmZvcm1hdGlvbi4KCkhhdmluZyBhcmdfcmV3cml0ZV9tb2RzIHBsYWNp bmcgbW9yZSBpbmZvcm1hdGlvbiBpbiB0aGUgYXJnLm9wYXF1ZQpmaWVsZCBpcyB0aGUgY2xlYW5l c3QgYXBwcm9hY2ggdW5kZXIgY3VycmVudCBzdGF0ZSBvZiB0aGUgYXJ0IChpbiBteQpvcGluaW9u KS4gSG93ZXZlciwgdGhlIHR3byBmaXJzdCBhbHRlcm5hdGl2ZXMgd29yayB3ZWxsIGVub3VnaCBm b3IKcGFzc2luZyBvbiBhIHN0cmluZyBmb3IgYSByZWRpcmVjdCBwYWdlLCB0aG91Z2guCg== |
From: <ca...@gm...> - 2006-11-08 04:02:14
|
Thanks allot Christian, this was very helpful! On 11/6/06, Christian S <ch...@gm...> wrote: > On 11/6/06, Count L=E1szl=F3 de Alm=E1sy <ca...@gm...> wrote: > > On 11/6/06, Christian S <ch...@gm...> 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 =3D A#arg.opaque, > Newarg =3D A#arg{opaque=3D[{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. > --=20 Cheers, L=E1szl=F3 |