Why do the spectra of quasars imply that they are extremely distant objects?
The distance of stars is measured by their red or blue shift.
Astronomers use the red/blue shift to measure the motion of a star, away/towards us respectively. Then they use a stars luminosity against known stars in the foreground and background to ascertain its relative distance. A common type of star used to measure distance is known as a Cepheid star. Cepheid stars all shine in a very tight window of luminosity and therefore provide a baseline for the star being compared.