Question: I know the differences between a **rangefinder** and a **SLR/DSLR** but what is the real reason to put a mirror in front of a lens to reflect light into the viewfinder? 

It raises lens prooduction price when you put extra distance between lens and sensor. So why do that? Does it improve image quality somehow? Isn't it logical to use rangefinders only?

Answer: 
Simple, it allows you to see exactly what the camera will "see" when you expose the shot.

Nir has given you a part of the argument as well which is accuracy.
In the "middle ground" of anything around mabye 20-100mm, building a rangefinder is not too difficult and Leica had adapters for longer and wider lenses if I am not mistaken. It takes some effort to calibrate but is doable.

However with an SLR you can use even more extreme focal lengths - try a 7mm or 15mm Fisheye lens, how do you get that into an extra viewfinder (which incidentally needs a similar lens system). Or maybe a 400mm, 800mm lens?
Every system is a compromise somewhere - and using a mirror to reflect the light from the lens to the viewfinder (or focussing screen if one is finicky) allows the user to fully exploit the flexibility that is offered by the range of available lenses.

Coming back to rangefinders, you might have noticed that lenses typically span around 20-135mm and I think there are is at least one lens that offers 17mm on Leicas as well.

The extra distance between the sensor and the lens is itself also not disadvantageous given the way that sensors are designed. Leica's sensor uses a specially shifted micro-lens arrangement to improve the light gathering capability of the sensor. Now whether it works is another discussion, in theory it should.
Moving the lens closer to the sensor means that the light hits the sensor at an oblique angle rather than a near right angle. Given the nature of "light wells" on a sensor, this increases light loss (hence the shifted microlenses on a Leica).

(This is actually the basis for this issue: <http://www.luminous-landscape.com/essays/an_open_letter_to_the_major_camera_manufacturers.shtml> )
Its tradition. When we had film cameras, a mirror system was used to give the photographer an accurate image of what the lens was seeing irrespective of which lens was attached. Obviously one could have a system with a live viewer. Old time photographers are used to looking in a view finder and composing an image.