Hi devs,

I wanted to rewrite URL beyond that what's currently possible with the CouchDB rewrite. I especially had in mind URLs where that need to conform to a certain standard and where you need a proxy in front of it to serve them up in that specific way. I have two use cases in mind.

First one with for wikis with subpages. You might want to have URLs like:
http://example.com/wiki/apache-projects/couchdb/info
as opposed to
http://example.com/wiki/apache-projects%2fcouchd%2f/info

While I tried this with JChris' Pages wiki, I found out that if a _show function is used, you can also have such URLs with the current rewriter (though directly accessing the documents with non URL encoded slashes won't be possible).

My second one is a TMS tilecache [1]. Those who don't know what it is, it's for serving up map tiles like Google or OpenStreetmap does. I would create a document per tile and attach the file to it. My URL would look like this (where "tile" is the attachement):
http://example.com/tilecache/3-5-2/tile
But I'd need an URL like
http://example.com/tilecache/tiles/3/5/2.png
(resp. http://example.com/tilecache/_design/tilecache/_rewrite/tiles/6/9/9.png)

My modification to the rewriter allows you to replace substrings with other ones. Here's the rewriter rule for this example:
{
    "from" : "/tiles/<x>/<y>/<z>.png",
    "to" : "..\\/..\\/:x/:y/:z/tile",
    "replace": {
        "old": "/",
        "new": "-",
        "limit": -1
    }
}

It replaces all occurences of "/" with "-" on the "to"-path. Two slashes ("\\") escape a character, so it won't be replaced. The "limit" parameter specifies how many occurences should be replaced. It could be either positive, then it will just count how often a string was already replaced and stop at the limit. If "limit" is negative, it will count from the back. This is especially useful if you want to replace slashes and know how many slashes the attachment has, but not how many the document has.

The changes are available here: https://github.com/vmx/couchdb/commit/889024df75892fb46a1e513e54466fa5bbe69e49

Comments please :)

[1] http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification

Cheers,
  Volker

Reply via email to