X-linked retinitis pigmentosa (XLRP) is generally a severe form of retinitis pigmentosa, a neurodegenerative, blinding disorder of the retina. 70% of XLRP cases are due to mutations in the retina-specific isoform of the gene encoding retinitis pigmentosa GTPase regulator (RPGRORF15). Despite successful RPGRORF15 gene replacement with adeno-associated viral (AAV) vectors being established in a number of animal models of XLRP, progression to human trials has not yet been possible. The inherent sequence instability in the purine-rich region of RPGRORF15 (which contains highly repetitive nucleotide sequences) leads to unpredictable recombination errors during viral vector cloning. While deleted RPGR may show some efficacy in animal models, which have milder disease, the therapeutic effect of a mutated RPGR variant in patients with XLRP cannot be predicted. Here, we describe an optimized gene replacement therapy for human XLRP disease using an AAV8 vector that reliably and consistently produces the full-length correct RPGR protein. The glutamylation pattern in the RPGR protein derived from the codon-optimized sequence is indistinguishable from the wild-type variant, implying that codon optimization does not significantly alter post-translational modification. The codon-optimized sequence has superior stability and expression levels in vitro. Significantly, when delivered by AAV8 vector and driven by the rhodopsin kinase promoter, the codon-optimized RPGR rescues the disease phenotype in two relevant animal models (Rpgr-/y and C57BL/6JRd9/Boc) and shows good safety in C57BL6/J wild-type mice. This work provides the basis for clinical trial development to treat patients with XLRP caused by RPGR mutations.