[plt-scheme] URL rewrite/dispatch in PLT Web server

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sat Mar 24 16:12:34 EDT 2007

Sridhar Ratna wrote:

>> > Also, does PLT web server support a way to rewrite urls (back and
>> > forth)? For example, the above url can instead be
>> > http://example.com/2006/02/foo-bar.html and k-urls like
>> > http://example.com/servlets;4*2*25232234/post can become
>> > http://example.com/post;k=4*2*25232234
>>
>> Yes, you can do that. Your servlet code sees URLs as strings, so it
>> can rewrite them anyway it wishes before sending them out. And, there
>> is a `dispatcher' API where you can route/rewrite the request object
>> before the standard servlet dispatcher gets it.
>
>
> I took a look at the source code. Seems like I need to edit them to
> add a new dispatcher, as it is evident by looking at this file,
> http://ja.soegaard.net/planet/html/collects/web-server/web-server-unit.ss
> As you can see there is code `specific' to each of the available 
> dispatcher.
>
> Or am I missing something?

Yes and no. As far as I know you can't get rid of the "/servlets/" part.
(Well, if you install Apache and let it rewrite the url before it gets
to the PLT web-server, then it is possible - and have been done)

But - if you make a servlet named "example" and put it in the servlets
directory, then

   http://example.com/servlet/example/foo/bar/baz/something.something-else

will invoke the example servlet, which can extract
   /foo/bar/baz/something.something-else
from the request structure with the help of request-uri.

-- 
Jens Axel Søgaard




Posted on the users mailing list.