Optimal redshift weighting for redshift-space distortions