Produce
Fruit flies are attracted to the smell of rotting or overly ripe produce. Things like bananas, squash, grapes, onions, fruit juices, cider, beer, potatoes, tomatoes or any other fruit or vegetable can become a feeding source for fruit flies. If you have fruit or vegetables that are sitting in the house and getting ripe, it is best to put these in the refrigerator to prevent attracting fruit flies. Any produce left out, from a forgotten potato or onion or fruit juice spilt on the floor or under the cabinet, can bring these insects into your kitchen.
Other Sources
Fruit flies are attracted mostly to ripened fruits and vegetables. However, they can also be attracted to other places that emit smells in the kitchen, such as drains or garbage disposals, trash cans, mops or cleaning rags. Anything that has come into contact with fermenting or decaying produce can attract these insects. All that is required is just a little bit of moist, fermenting film.
Fermentation
The reason fruit flies are attracted to decaying fruits and vegetables is because of the fermentation process. Yeasts break down sugars and produce alcohol and carbon dioxide. Fruit flies are attracted to the carbon dioxide released during fermentation, according to the University of California at Berkeley. This is why beer, carbonated fruit drinks and even wine can attract fruit flies.
Elimination
Eliminating fruit flies can be extremely difficult. Female fruit flies can lay up to 500 eggs and will lay them on any food source. The most important part of eliminating fruit flies is removing any possible food source. Properly storing produce, securing opened drink containers and properly cleaning will help you accomplish this. Once all potential food sources have been removed the fruit flies will die naturally within a few weeks. This can be supplemented with traps that attract and capture the insects.