Cities are not uniformly healthier than rural communities. It depends on a whole range factors, including the overall wealth and infrastructure provided by the country or state in which you are located. For instance, in cities you might face more smog and pollution and crime, but in rural areas you might drive more miles on dangerous roads or work with hazardous farm equipment, or be exposed to more chemicals in the ground water or sprayed on the crops. Cities often have much more rapid spread of communicable diseases, while clean water might be harder or more expensive in rural communities.
Globally, the top factors for length of life include clean water, food security, adequate housing, vaccines, health care access (especially maternal, prenatal, and infant), safe roads and neighborhoods, low crime, violence, and armed conflict, low access to firearms and weapons, good schools, and strong social support system (so if any of the above fails, there is a system to prevent a hard landing). It is possible to achieve all of these things in both cities and in rural areas; cities and rural areas have different challenges in achieving them, though.