Don't overfeed worms. Burying the food will help keep unwanted pests and pets from intruding on your bin. Keep bedding material moist, but not too wet. Overly wet conditions encourage the proliferation of fruit flies. Wet conditions might also cause an odor problem, as anaerobic bacteria thrive when it is too wet.
Feed worms a varied diet.
If citric foods dominate the bin, the bin may become too acidic, which may attract fruit flies. Loosely place a piece of plastic or a sheet of newspaper inside the bin on top of the worm bin contents. Limit citrus fruits. Remove rotten food from the bin when fruit flies are present. Fruit flies often lay their eggs on decomposing food.