The research investigated the effect of socioeconomic status, gender, perceived parental influences, teacher affective support, classroom instruction and previous achievement on students' attitude towards mathematics. The comparison of these effects was also done between urban and rural school students. This research employed a cross-sectional quantitative design based on a structural equation modelling approach. The sample consisted of 808 students from ten secondary schools in Sabah, three of which were urban and seven were rural schools. Findings showed positive relationships exist between perceived parental influences (r = .231), teacher affective support (r = .242), classroom instruction (r = .439), and previous achievement (r = .284) with students' attitude towards mathematics. The multigroup analysis for urban and rural students showed similar results as the whole student group. However, for urban students, classroom instruction (r = 0.352) and previous achievement (r =-0.363) had the greatest impact on attitude towards mathematics. For rural students, the highest impact on attitude towards mathematics was from classroom instruction (r = 0.452) and teacher affective support (r = 0.246). The least impact for both groups was perceived parental influence. This study implied that factors affected students' attitude towards mathematics in rural and urban secondary students are different.