In the medieval period Rampur was usually controlled by the current ruler of Delhi and was divided between Badayun and Sambhal districts. Being situated in the Northern part of Rohilkhand, it was known by the name of Kather and was ruled by Katheria Rajputs. The Katheria Rajputs fought for about 400 years with the rulers of Delhi and later with the Mughals. They fought against Nasiruddin Mahmud in 1253, Ghiyasuddin Balban in 1256, Jalaluddin Firoz in 1290, Firoz Shah in 1379 and Sikander Lodhi in 1494. In 1623 two Afghan brothers of the Rohilla tribe, Shah Alam and Husain Khan, settled here and founded a small state, bringing with them many other Pashtun settlers. Ali Muhammad Khan, grandson of Shah Alam, united the Rohillas between 1707 and 1720, making Bareilly his capital. His uncle, Hafiz Rahmat Khan, who succeeded him, extended his power from Almora in the North to Etawah in the South-West.