Hm, okay. Doing all of this within the same context is probably more complicated, and not exactly what I've had to do in the past. Would moving to a multi-context setup make sense in your situation, or even be a possibility? The reason I ask is, I've found that this is the sort of situation where contexts really excel -- you're able to uniquely identify pages and groups of pages by their context, and also apply context-level settings that will override system settings.
For example, I mentioned FreshLinks, which solves my contextual linking problem. Pretend for a second that your site is using the same subpath context-routing plugin I mentioned, so each of your contexts can be accessed at site.com/context1/, site.com/context2, etc. Here's what FreshLinks does:
1. Executes on OnWebPagePrerender, so all [[~id]] links have already been converted into URLs in the HTML.
2. Gets the first subpath of the page URL
3. Gets a reference to the page output, and finds every link on the page (with a few restrictions that keep it from being too "greedy" with certain URL patterns).
4. Loops through all of the links it finds, and compares the first subpath of each link URL to the page URL subpath it finds in step #2.
5. If there's a match in #4, it does nothing (i.e., you're already linking to the correct context). If there's not a match, it updates that link to the subpath in #2 (i.e., the current context).
6. Returns the new, modified page output.
The problem is, if you're not using contexts, I'm not sure what's "unique" about your URLs, without creating an array map as you suggested. That's definitely possible, but seems a lot more complicated than letting the contexts sort things out automatically.
Again, FreshLinks (at this point anyway) is pretty custom to my site setup and still has a few bugs I need to work out, but here it is if you want to see it:
https://gist.github.com/3953786.
EDIT: I said in step #2 that I got the page's URL subpath. If you look at my script, I'm actually getting the context key and massaging it a little bit, but either way should work.
[ed. note: aladage last edited this post 14 years ago.]