The synthesis of a series of 6-substituted 2-pyrrolyl and 2-indolyl benzoxazoles by photostimulated C-O cyclization of anions from 2-pyrrole carboxamides, 2-indole carboxamides, or 3-indole carboxamides has been found to proceed in good to excellent yields (41-100%) in DMSO and liquid ammonia. The pyrrole and indole carboxamides are obtained in good to very good isolated yields by an amidation reaction of different 2-haloanilines with 2-carboxylic acid of pyrrole and 2- or 3-carboxylic acid of indole. To explain the regiochemical outcome of these reactions (C-O arylation vs C-N or C-C arylation), a theoretical analysis was performed using DFT methods and the B3LYP functional.