Hi Frank, Thankyou very much for sugessition. It works perfectly, except that i had to change $r->headers_out(...) to $r->err_headers_out(...) (not sure why, could have been a testing problem on my end...)
I was hoping to not use a PerlTransHandler as then for every request i will be running that bit of code, was hoping to use handlers from within an apache LocationMatch directive, but hey, the TransHandler works :-) thanks, simran. On Wed, 2003-09-24 at 18:30, Frank Maas wrote: > > Hi All, > > > > What i am trying to do is: > > > > * If a user goes to http://myhost/[A-Za-z]{3}[0-9]{3} (eg. > > http://myhost/abc123) > > > > Then i want to redirect them to "/" and set their cookie based on > > where they tried to go (eg. set cookie Referer=abc123) > > Why do you want to do this? Is the cookie used while '/' is served? > What is serving '/'? Is it a file (/index.htm or something) or a > handler (and if so: a PerlHandler?). If you are really only interested > in serving the cookie and (the unrelated) /, then you can use a > TransHandler. > In the code fragment below I not only set a cookie, but also use > notes(). With this you can 'ship' information from one stage to > the other. In this case you can use it in your handler, so in that > handler you should check for notes(Referer) and if that does not > exist check for a cookie. > > Hope this helps > > --Frank > > # httpd.conf - not inside a container (like Location) > PerlTransHandler MyModule::Handlers::pathinfoToCookie > # --------------------------------------------------- > > # MyModule.pm > sub pathinfoToCookie { > my $r=shift; > if ($r->uri() =~ m!^/([A-Za-z]{3}[0-9]{3})!) { # request like /abc123 > $r->uri('/'); # set uri to / > $r->header_out("Set-Cookie", "Referer=$1"); # and create cookie > $r->notes(Referer => $1); # and set the notes > } > return DECLINED; > } > # ---------------------------------------------------- >