The rice leaffolder, Cnaphalocrocis medinalis Guenee (Lepidoptera: Pyralidae), is a rice pest that is prone to outbreaks when high levels of nitrogen (N) fertilizer are applied to rice. The larvae feed by scraping the mesophyll cells of leaves, which are mainly composed of chloroplasts containing significant levels of elemental magnesium (Mg). To determine the cause of N fertilizer-induced rice leaffolder outbreaks and the effects of Mg and Mg uptake on the rice leaffolder, the changes in the life history traits and biochemistry of C. medinalis larvae feeding on rice leaves treated with different Mg and N concentrations were investigated in this study. The results showed that foliar treatment using different Mg concentrations under hydroponic culture conditions significantly decreased the developmental duration (days) (DD) of the larvae and pupae but did not influence the pupation rate or adult emergence rate. The number of eggs laid by adult females and the protein content and total sugar content in the larvae and pupae significantly increased with increasing Mg concentrations. Under soil culture conditions, the DD for the larvae and number of eggs laid by adult females significantly increased with increasing nitrogen fertilizer levels, but the applied fertilizer did not influence the DD in the pupae, pupation rate, or adult emergence rate. In contrast, the DD for adults decreased with increased fertilizer levels. In hydroponic culture, Mg in the culture solution and Mg foliar sprays significantly increased the Mg content in rice leaves. In soil cultures, the use of N fertilizer and Mg foliar spray did not significantly increase the leaf Mg content, except at a concentration of 12.5 g/L, indicating that the leaf Mg content may be related to the root uptake of Mg.