How to Get Rid of Fruit Flies
Fruit flies can develop anyplace where fermenting organic matter stays moist, such as a slow-moving or seldom-used sink or shower, a floor drain with buildup, or on spoiled produce. Like other flies, fruit flies develop from larvae, and fruit-fly larvae must have moist, fermenting organic matter in order to survive. Therefore, the best protection is to throw away spoiled produce and unclog drains. Then try these tips from "Martha Stewart's Homekeeping Handbook."
Trap the flies in a jar: First place a small piece of ripe fruit or a few drops liquor or beer in an open jar, and then place a paper funnel (such as a coffee filter with the tip snipped off) in the top. The fruit flies will fly in and become trapped. You can kill them by pouring in boiling water.
Another option is to set out a shallow dish of apple-cider vinegar. Cover the bowl in plastic wrap; using a needle, punch a half dozen holes in the surface at least a half inch in from the edge of the bowl. As with the paper-funnel method, the fruit flies will fly in and get trapped.
Keep a few sprigs of fresh basil in a bowl or a potted basil plant near fruit and vegetables. Many cooks use this time-honored method with good results; some even find that setting a pot or two of basil outside the kitchen door keeps flies from entering the room.