In my fantasy world, I have a really, really big city where trade and people flows are done through magic gateways. Partly as to not let whole districts suffocate in poverty (among other bad things), but also because it is basically the only way to reach it. The gateways are made -and maintained continuously- by trained mages and artifacts, and link two realms of reality together. A mage alone can open a portal enough to make a rider and its horse pass for a short time, 3 or 4 can make whole carts get through them. Artifacts on their side, mostly help in maintaining the portal for longer durations (think hours). Most models are not that big, though they cannot be carried in a pocket.
Now! Now! A big, rich trade center is the source of all... "interested" and, uh... "unwanted" neighbors (well, sort of, they're not physically next to the city), so a wise ruler need to plan some defensive structures in case things go south. Especially if an army manages to make a breach somehow and take over portal stations. Or create their new ones by sabotaging whatever "I don't like portals" gizmo in the city.
In order to prevent this (and because of its history), the town is divided in several quarters, separated by strong, fatty walls1. These structures are capable of repelling intruders from one side then another2, since you don't know from which district they will come from. In other words, the two sides are heavily protected. This means that you can reasonably contain an opponent inside a single district, which is considerably better than letting them spread wherever they want.
All is good and nice until you try to take back the districts you have lost. Indeed, now, you need to attack your walls, protected by your enemies. Ain't that neat.
Therefore, how can one prepare for this eventuality and protect their walls from such robbery, or at least minimize their defensive value?
In particular, I'd wish :
- To reduce damage to buildings, especially the walls, since they are quite expensive in sheer resource quantity. Other potential losses are more acceptable, like sacrificing a squad for the sake of the city.
- To avoid basing the strategy solely on hidden intel (e.g. : secret passage ways). I've thought about this already, and find it quite a risky move if your enemy has spies and hear about them.
- To be an enough general approach to take them back. You mainly have to know there's a threat sitting on your walls and another one behind it.
- The longer they are prevented from using effectively the walls against you, the better it is. Or make them unavailable when you want to take them back.
- Limit to medieval fantasy technology. No electricity, oil or steam, but you can use clever mechanical and chemical concepts (cogs, pulleys, greek fire, even some gases...). While there's magic, use it only for non-lasting enchantments to create your devices or to trigger them. Otherwise that makes too many possible answers, 'specially without any detail on how my magic works.
However, you can plan any kind of structure or strategies you can think of, inside or outside the walls. Also, the town guards can set up something when they notice things are not going well for them, so you have some time to trigger traps or other devices, during a whole day or maybe even two. Indeed, the city is big, and the town's defense is tough and organized. In some way, it is a little like laying siege on fortifications, but you choose your walls and spend one day in them before. Remember that they need to be defendable before the counter-attack!
For instance, one plan I thought of is to build trebuchets on the two sides, then to sabotage the ones in the district you are losing. Afterwards, take back the walls by using the remaining trebuchets on the other side. It's clearly not ideal because of the damage it would do and the efficiency -they're still using the walls against you-, but you have the gist of what you can do and what I am looking for!
So given this configuration and constraints, what better plan than mine would you think of to take back what's rightfully yours, wise ruler :)? Hopefully you can find an answer, this question may not be easy!
Question clarification addendum
I need to point out that what the main difference with traditional besieging lies in is that you can prep things up before the invasion. I know how to lay a medieval siege (well, the common tactics at least), and some basic research would be enough in any case ^^.
In traditional warfare, being able to set things up in advance gives a huge advantage, be it by putting traps or denying key structures or resources (see scorched earth tactics and mine fields for instance). So, what is more interesting is to know how can one help themselves as much as possible if they have some time to prepare things on the fortifications or around for a counter-attack. Put differently, if you have time to prepare things in, on, under and next to the walls, what would you prepare to help you out in regaining these?
Note that even though the easiest idea would be to make purely impregnable walls so that it never happens in the first place, as we all know, you can always create an opening with enough efforts, and you're never too careful :).
Magic Addendum
Since you like very much magic portals, here's some additional intel on how it works : To be perfectly safe, this magic must be cast on a path the caster knows (start+end points), so this limits how many points you can reach with one gate master. Everyone on the gate's path will sense it and any mage can create an interference zone, making it dangerous and unstable by default. Walk blind-sighted along a cliff's border and stop exactly before the fall, on an unstable terrain and while screaming where you are, and that's what traversing such a gate will feel. With a gate expert, you might teleport someone into an interference zone, but it is risky. Also, note that gate mages are not that many, since it is difficult by default and require practice and experience.
Last important bit of information, you may be able to place portals anywhere you want, but some places are much easier to work with than others. Only true gate masters are able to memorize and create portals anywhere, and such are rare and priced
Notes
1: There are also smaller walls/defenses around the portal stations, if you ask, but they may get overrun by a determined, full force army.
2: One side, then another one. While they "might" withstand a two-way attack, and even though it may be useful to have a safe path between two free districts separated by enemy territories, it's really, really hard to take in attacks from both the front and your back on such a thin line.