Short answer. Where the property is located. Actions affecting title to or possession of real property, or an interest in it, are commenced and tried in the court with jurisdiction over the area where the property, or a portion of it, is situated — not where either party resides.
What the law says
Actions affecting title to or possession of real property, or interest therein, shall be commenced and tried in the proper court which has jurisdiction over the area wherein the real property involved, or a portion thereof, is situated.
Rule 4, Section 1 — Venue of real actions. Read the full provision →
Real actions follow the property, not the parties
This is the key distinction from personal actions: actions affecting title to or possession of real property, or interest therein, must be filed in the court with jurisdiction over the area wherein the real property involved... is situated. Residence of the plaintiff or defendant, which controls venue in personal actions, has no bearing whatsoever on venue in a real action at all.
A portion of the property is enough to fix venue
The rule accounts for property spanning more than one jurisdiction: venue is proper where the property, or a portion thereof, is situated. A plaintiff does not need the entire parcel to lie within one court's territory — if any part of it falls within a court's jurisdiction, filing there satisfies the venue requirement for the whole action against every defendant.
Forcible entry and detainer cases have their own, more specific version of this rule
The rule singles out ejectment cases for a more specific formulation: forcible entry and detainer actions shall be commenced and tried in the municipal trial court of the municipality or city wherein the real property involved, or a portion thereof, is situated. This pins ejectment cases specifically to the municipal trial court level, rather than leaving the court level open the way the general real-action rule above does.
Why getting this right matters before filing
Filing a real action in the wrong venue — for instance, in the plaintiff's own city rather than where the property sits — risks the case being challenged and potentially dismissed or transferred, wasting the time already invested in getting the case underway. Before filing any case concerning land, confirm the property's actual location and file with the court that has territorial jurisdiction over it, not the court most convenient to either party personally, whatever that convenience might be.
This territorial focus is the single most important thing to check before drafting the complaint itself, since getting it wrong can undo everything that follows and force the entire filing process to start over again from scratch.