Houseflies usually breed in garbage and animal manure. If you've noticed a sudden infestation of flies, immediately take out your trash and change any pet litter pans in your home. Eliminating the breeding area should help to control the infestation. To prevent future fly breeding, place your garbage, especially kitchen scraps, in trash bins with tight-fitting lids. Remove your trash at least once per week, and remove clumps from litter boxes every day or two.
Flies are attracted to sugar, so you can make your own traps to lure and kill houseflies in your home. Mix a solution of sugar and cider vinegar in equal parts, and brush it around the lip of an empty beer or soda bottle. Fill the bottom 1 to 2 inches of the bottle with water using a funnel to prevent washing off the sugar mixture. The sugar and vinegar will lure flies into the bottle, where they'll drown in the water. Another option is to fill an empty wine bottle with mango peels. Flies will be lured into the bottle, where they'll get stuck and die. White wine works particularly well.
You probably don't keep flypaper lying around the house, but you can make your own with a few kitchen staples and brown paper grocery bags. Mix equal parts water, sugar and corn syrup in a saucepan on your stove. Heat the mixture until it begins to bubble. The liquid should be thick and sticky. Cut a brown paper bag into 10-by-2-inch strips. Coat the strips with the sugar liquid, and place them in areas where you frequently see flies. Most fly activity occurs near the floor, so place your homemade flypaper along baseboards or in your windowsills. Replace it once it is covered or is no longer sticky to the touch.
Most houseflies enter your home through windows, doors and other openings to the outside. While you can't prevent all flies from getting in, you can create barriers to reduce the number of adult insects entering your home. Install screens on your windows and patch existing screens that have developed holes. Keep your doors closed. Examine your home thoroughly for cracks and gaps leading outside, and caulk or cover them to keep out pests.
You'll have an easier time keeping flies out of your home if they're not attracted to it in the first place. When you take out your trash, place it in a sealed plastic bag as far away from the entrance to your home as possible. Clear your yard of pet droppings and any fallen fruit from trees at least once per week. Don't allow your trash to accumulate. Put it out to be collected each week.