The best way is not to have them in the first place! Fruit flies are attracted to the JUICES of fruits. If you buy whole, unblemished fruit (not “ugly ducklings”), you shouldn’t have a problem. Keep an eye on fruit that is ripening; use it or refrigerate it as soon as you notice fruit flies moving in.
Dispose of peelings and pits promptly and properly. Outside, in a compost pile, is best. Next best: inside a sealed, airtight container until garbage day. Wipe up any spilled juice immediately. Rinse out the sink after preparing fruit. If you just throw the peelings and pits into your garbage, you will attract fruit flies very rapidly.
If you already have fruit flies, we’ve heard that the best way to deal with them is to set out a bowl of vinegar, covered with plastic wrap that has some holes punched in the top. The fruit flies are supposed to make their way in and drown before they make their way out.
Take heart–winter comes every year! Then we’ll have no more mosquitoes, flies, or fruit flies bothering us!