Carbon nitrides are among the most efficient and extensively studied transition-metal-free photocatalysts, yet their industrial application is limited by high charge recombination, poor charge transport, and insufficient absorption above 460 nm. This study investigates how fine-tuning the crystal structure of carbon nitrides helps to overcome these challenges and to enhance their photocatalytic performance. We used poly(heptazine imides) (PHIs) with various cations (M = H⁺, Na⁺, K⁺, Mg2⁺) as a model system. Na-PHI exhibits the highest activity among PHIs with monovalent cations, as the combination of solvated Na⁺ cations and rotational defects, experimentally observed in this study for the first time, optimizes interlayer charge transfer. Greater photocatalytic efficiency observed for Mg-PHI is attributed to the preservation of rotational defects and the higher oxidation state of Mg2⁺, which enhances charge density and facilitates charge transfer. Density functional theory (DFT) and spectroscopic analyses reveal that Na-PHI and Mg-PHI share a valence band dominated by nitrogens and a conduction band primarily influenced by carbons, with both cations contributing to n-type doping. Mg-PHI features sub-gap impurity states, reducing the band gap and extending light absorption. Excited-state molecular dynamic simulations further demonstrate that water molecules contribute more significantly to charge transfer. highlighting an additional key factor in optimizing photocatalytic performance.