The influence of disorder and localization on optical dephasing of excitons in the semiconductor mixed crystals CdS1-xSex and AlxGa1-xAs has been investigated by means of time-resolved four-wave mixing and photon echo experiments. A dephasing time of several hundreds of picoseconds is found for resonantly excited localized excitons in CdS1-xSex while the dephasing time in AlxGa1-xAs amounts to only a few picoseconds. In CdS1-xSex dephasing results mainly from hopping processes, i.e., exciton-phonon interaction. The contribution of disorder is negligible in terms of phase relaxation in CdS1-xSex. In contrast, in AlxGa1-xAs elastic disorder scattering yields an essential contribution to the dephasing rate. We present a theoretical model, which treats dephasing of optical excitations in a disordered semiconductor, including the influence of disorder as well as exciton-phonon interaction. On the base of this model, the experimentally observed differences in the dephasing behavior of excitons in CdS1-xSex and AlxGa1-xAs are related to the microscopic structure of the disorder potential and the mechanism of exciton localization.