mozilla/kuma — pull request #1386 by lmorchard (2013-09-17 16:57:30+00:00)
Title: bug 912084: Redirect/rewrite Middleware for zones

DO NOT MERGE (yet? unless it looks sane?)

This PR adds an `url_root` field to `DocumentZone`. When set, the included middleware alters the URL at which the docs under that zone are served.

Spot checking:

* Consider a doc at `/Zones/AppsPages/Foo`, where `/Zones/AppsPages` is a parent doc and has been converted to a content zone.
* Set `url_root` on on the `DocumentZone` for `/Zones/AppsPages` to `Apps`.
* The doc originally at `/Zones/AppsPages/Foo` should be accessible at `/Apps/Foo` thanks to an internal path rewrite
* Any attempt to load `/Zones/AppsPages/Foo` directly should result in a 301 redirect to `/Apps/Foo`
* Try adding URL params - `/Zones/AppsPages/Foo?raw=1` should redirect to `/Apps/Foo?raw=1`
* Clicking editing buttons & etc should end up at the right rewritten URL, albeit after a redirect
* In the database, docs still live at their original URLs, which might be confusing but I can't think of a good way around it. Also, removing `url_root` or the `DocumentZone` altogether should reverse the rewrite effect.

What this PR does **not** do is rework all the link construction for pages. So, links within the site will still point at original wiki URLs (eg. `/Zones/AppsPages/Foo` instead of `/Apps/Foo`). Getting all those links in synch will take some work, so I wanted to get some feedback on this general middleware approach first.

So... is this crazy?