Preheat your oven to 375°F.
Cook the rigatoni according to package instructions until al dente. Drain and set aside.
In a large skillet, heat the olive oil over medium heat. Add the diced onion and sauté until translucent, about 5 minutes.
Stir in the minced garlic and cook for an additional minute until fragrant.
Add the chopped spinach to the skillet and cook until wilted, about 3-4 minutes. Remove from heat and let cool slightly.
In a large bowl, combine the ricotta cheese, 1/2 cup of the mozzarella cheese, 1/4 cup of the Parmesan cheese, egg, oregano, salt, black pepper, and red pepper flakes (if using). Mix well.
Stir in the cooked spinach and onion mixture.
In a large baking dish, spread a thin layer of marinara sauce on the bottom.
Add the cooked rigatoni to the ricotta mixture and stir to combine.
Pour the rigatoni mixture into the baking dish and top with the remaining marinara sauce.
Sprinkle the remaining mozzarella and Parmesan cheese on top.
Cover the baking dish with aluminum foil and bake for 25 minutes.
Remove the foil and bake for an additional 15 minutes, or until the cheese is bubbly and golden.
Let the baked rigatoni cool for 5-10 minutes before serving.