A complex microbiota inhabits various microenvironments of the gut, with some symbiotic bacteria having evolved traits to invade the epithelial mucus layer and reside deep within the intestinal tissue of animals. Whether these distinct bacterial communities across gut biogeographies exhibit divergent behaviours is largely unknown. Global transcriptomic analysis to investigate microbial physiology in specific mucosal niches has been hampered technically by an overabundance of host RNA. Here, we employed hybrid selection RNA sequencing (hsRNA-Seq) to enable detailed spatial transcriptomic profiling of a prominent human commensal as it colonizes the colonic lumen, mucus or epithelial tissue of mice. Compared to conventional RNA-Seq, hsRNA-Seq increased reads mapping to the Bacteroides fragilis genome by 48- and 154-fold in mucus and tissue, respectively, allowing for high-fidelity comparisons across biogeographic sites. Near the epithelium, B. fragilis upregulated numerous genes involved in protein synthesis, indicating that bacteria inhabiting the mucosal niche are metabolically active. Further, a specific sulfatase (BF3086) and glycosyl hydrolase (BF3134) were highly induced in mucus and tissue compared to bacteria in the lumen. In-frame deletion of these genes impaired in vitro growth on mucus as a carbon source, as well as mucosal colonization of mice. Mutants in either B. fragilis gene displayed a fitness defect in competing for colonization against bacterial challenge, revealing the importance of site-specific gene expression for robust host-microbial symbiosis. As a versatile tool, hsRNA-Seq can be deployed to explore the in vivo spatial physiology of numerous bacterial pathogens or commensals.