Because of its strategic location along important infrastructure lines, and because of flourishing trade, the town grew rich. This allowed a certain degree of freedom (especially within the Habsburg-controlled territories and) within the Swiss Confederation which ended with the formation of the Swiss cantons by Napoleon in 1799. In 1656 and 1712 (the First War of Villmergen and the Toggenburg War, or Second War of Villmergen, respectively), Rapperswil was involved in wars between the Catholic and Reformed cantons of the Old Swiss Confederation. Rapperswil was at first part of the Helvetic and the canton of Linth's capital city. After the 1803 Act of Mediation, it joined the canton of St. Gallen, and the former "Herrschaft Rapperswil" was split into the municipalities of Rapperswil and Jona.