Flags and rules
I wrote the SailNet article that was linked earlier (it's based on the relevant section in The Annapolis Book of Seamanship, which I wrote). Outside of guidelines and traditions, the only universal rule is that outside US waters there's only one official American flag, and that's the stars and bars. Skippers who like the yacht ensign should carry both types when they cross borders.
Some yacht clubs call for the stars and bars all the time. What drives traditionalists crazy is seeing the yacht club burgee flying from the starboard spreader. If you want to do it 100% right, get an extra tall pig stick to hoist to the masthead on a Dacron flag halyard with an extra-sturdy block up there. (Nylon stretches so much you probably won't be able to get the stick to stand straight up straight so the burgee's above the masthead instruments.)
It's not illegal to put the ensign on the mainsail or mizzen leech. But it doesn't make much sense to do it if you can't get it down in a hurry to prevent fraying by the backstay or topping lift. You can have the sailmaker punch a grommet or sew a small block into the leech about 2/3 of the way up. Run a flag halyard through it and secure it to the end of the boom. And be prepared to make adjustments.