Where is this place "city on the rock"?
The photo was taken in Ronda, Andalucía, Spain.
Ronda is a very touristic town, in particular around the bridge, which is its main tourist attraction. You can get there by train from Antequera or Algeciras, or by bus from Sevilla, Malaga, or smaller towns closer-by.
The bridge is called Puente Nuevo. Here is the same bridge from another angle:
For a large gallery of photos, see Wikimedia Commons on Puento Nuevo de Ronda.
P.S. Be careful if you want to rent a car in Ronda!