Over the thousands of years Humankind has dealt with garbage and other wastes, they have had to deal with the biological duties of Flydom. Though flies are dirty and carriers of disease, the world would be buried in crap and carcasses if it weren't for their intervention. However, they carry disease and are really dirty, so control is an issue.
Some of the earlier controls were to take a certain poisonous mushroom and float it in milk, stinky baits with a similar funnel setup, sticky traps, and the Dog. These forms are not pragmatic for whatever reason, the dog gets full, it takes days to get the stink just right, the stink is stinky, and lack of mushrooms come to mind.
This trap is pleasant enough to keep in the house and works much better, is more efficient, than any of the other methods commonly used.
Step 1: Fly Behavior
The easiest way to do this is to find a big pile of dog crap in the yard and watch it closely. This is a great activity for the family and friends over a few beers during a cookout. We usually cut out little fly wings for the kids and play games like "catch the fly" where one of them takes off making buzzing sounds and have all the other kids chase after them with nets. The dogs join in and it's just fun all around. Anyway, if you watch long enough you will start to see things like me, and realize that when flies get done with whatever they do there, they do two things:
1) They fly straight up.
2) They go towards the light.
See, when flies handle their sacred (Sacred to Flies. What did you think I meant?) functions in the great scheme of life, they seek out stinky dead things all over. If it happens to be in a tight place, they crawl around following the smell until they get to the spot they need to be. Getting back out is a little harder, because in an enclosed space they can't smell anything but stinky, so follow the light. Now you know why they always seem pretty stupid about realizing they can't get out THROUGH the window glass.
The other problem flies have is nobody seems to think of them as pets. Either somebody is trying to eat them, or just plain doesn't like them for some reason. Understandably, they have a real persecution complex, so over the millions of years they've been in existence have developed these paranoid responses which, noting their habits, have worked out pretty good for them.
Beyond the fact that his egress is not likely to be down and under that pile of poop, the most vulnerable time for our leetle friend is when he's taking off. Considering the shortest distance between two points is a straight line, getting airborne is simply a matter of getting there fast. Now catch him.