On Earth, microorganisms living under intense ultraviolet (UV) radiation stress can adopt endolithic lifestyles, growing within cracks and pore spaces in rocks. Intense UV irradiation encountered by microbes leads to death and significant damage to biomolecules, which also severely diminishes the likelihood of detecting signatures of life. Here we show that porous rocks shocked by asteroid or comet impacts provide protection for phototrophs and their biomolecules during 22 months of UV radiation exposure outside the International Space Station. The UV spectrum used approximated the high-UV flux on the surface of planets lacking ozone shields such as the early Earth. These data provide a demonstration that endolithic habitats can provide a refugium from the worst-case UV radiation environments on young planets and an empirical refutation of the idea that early intense UV radiation fluxes would have prevented phototrophs without the ability to form microbial mats or produce UV protective pigments from colonizing the surface of early landmasses.