Brindisi Airport (Aeroporto del Salento): Best value: take the airport bus into Brindisi railway station, then a Trenitalia regional train to Ostuni (about 20 minutes), followed by a local bus or short taxi up from Ostuni station to the centro storico. Allow roughly 1 hr 15 min to 1 hr 45 min door to door and about €5–10 before the final taxi. With luggage or an evening arrival, pre-book a car transfer instead: about 35–45 minutes; taxis are usually far more expensive than public transport.
Bari Karol Wojtyła Airport: Useful mainly if flights are substantially cheaper. Take the airport train/bus into Bari Centrale, then a Trenitalia regional train south to Ostuni (the rail leg is about 50 minutes). Allow around 1 hr 45 min to 2 hr 15 min in total and roughly €10–15, plus the final 3 km from Ostuni station to the old town. A rental car is sensible only if Ostuni is a base for the Valle d’Itria and coast.
Ostuni railway station: Trenitalia’s Adriatic line is the practical rail gateway: Brindisi is about 20 minutes, Lecce about 45 minutes and Bari about 50 minutes. The catch is important: the station is in the newer commercial area, around 3 km north of the historic centre. Check the local bus timetable for your arrival; otherwise take a taxi for the final uphill stretch rather than trying to drag luggage up to the white town.