The territory was under Portuguese rule between 1297 ( Treaty of AlcaÃ ices ) and 1801 . Then , it was occupied and ruled by Spain .
As OlivenÃ a , the town was under Portuguese sovereignty between 1297 ( Treaty of AlcaÃ ices ) and 1801 when it was occupied by force by Spain under the Treaty of Badajozthan legaly retroceded to Portugal by Spain in 1817 when they subscribed Versailles Congress of 1815 - which Sapin never respected .