This project is read-only.

URL Rewrite

Jul 20, 2011 at 6:33 PM

Is it possible to do URL rewrites with this web server?  I am using it now and it is working great, but I want to also create a REST API and need to be able to to do URL rewrites.  Any info would be appreciated. 

Jul 20, 2011 at 6:49 PM

You can use routers.

They can either send redirect responses or just change the uri in the request to anything you like.

Jul 20, 2011 at 9:04 PM

Thanks jgauffin.

Would you mind explaining a little how I would go about getting this working.  I want users to be able to access my api in the following way:   I then want this request to get rewritten to in order to process the api call.  How can I do this using routers like you suggest?

Aug 2, 2011 at 11:35 PM
Edited Aug 3, 2011 at 9:24 AM

The RegExRouter is exactly what you're looking for:

You can use a regular expression like /api/(?<cmd>[a-zA-Z0-9]+)/(?<arg>[a-zA-Z0-9]+) and then use the named captures, so you get something like 


IRouter router = new RegExRouter(
    "/api/(?<cmd>[a-zA-Z0-9]+)/(?<arg>[a-zA-Z0-9]+)", // from
    "${cmd}&arg=${arg}", // to
    false); // do not redirect, just rewrite the request uri