In food webs, many interacting species coexist despite the restrictions imposed by the competitive exclusion principle and apparent competition. For the generalized Lotka-Volterra equations, sustainable coexistence necessitates nonzero determinant of the interaction matrix. Here we show that this requirement is equivalent to demanding that each species be part of a non-overlapping pairing, which substantially constrains the food web structure. We demonstrate that a stable food web can always be obtained if a non-overlapping pairing exists. If it does not, the matrix rank can be used to quantify the lack of niches, corresponding to unpaired species. For the species richness at each trophic level, we derive the food web assembly rules, which specify sustainable combinations. In neighboring levels, these rules allow the higher level to avert competitive exclusion at the lower, thereby incorporating apparent competition. In agreement with data, the assembly rules predict high species numbers at intermediate levels and thinning at the top and bottom. Using comprehensive food web data, we demonstrate how omnivores or parasites with hosts at multiple trophic levels can loosen the constraints and help obtain coexistence in food webs. Hence, omnivory may be the glue that keeps communities intact even under extinction or ecological release of species. 