Rectal spasms why and how to fix?

Depends. If you are talking anal sphincter spasms, you may have a fissure and that needs diagnosis and treatment. True rectal spasms could be proctalgia fugax, a difficult diagnosis and even harder to treat but often eventually goes away on its own. See a colorectal surgeon to be sure of diagnosis and obtaining proper advice.