Preheat oven to 425 degrees F (220 degrees C). If using dark-coated muffin pans, preheat oven to 400 degrees F (200 degrees C). Grease 12 muffin cups.
In a large bowl, stir together flour, sugar, salt, baking powder, and rosemary until the mixture is smooth and without lumps. Lightly mix in the mozzarella cheese, Parmesan cheese, onion, and garlic. In another bowl, whisk together the egg and melted butter, then whisk into the milk. Make a well in the center of the dry ingredients, and pour the milk mixture into the well. Stir just to moisten, 12 to 15 full circular strokes that scrape the bottom of the bowl. The batter will look lumpy. Pour batter into the prepared muffin cups, filling them about 2/3 full.
Bake the muffins in the preheated oven until browned, about 25 minutes. Cool in pan for about 5 minutes before removing from the cups.