Preheat your oven to 375°F (190°C).
Cook the rigatoni pasta 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.
Add the minced garlic and cook for an additional minute until fragrant.
Stir in the ground beef or Italian sausage, breaking it apart with a spoon. Cook until browned and cooked through, about 7-10 minutes. Drain excess fat if necessary.
Add the dried oregano, dried basil, red pepper flakes (if using), and marinara sauce to the skillet. Stir to combine and let simmer for 5 minutes.
In a large bowl, mix the ricotta cheese, half of the mozzarella cheese, Parmesan cheese, egg, salt, and pepper until well combined.
In a greased 9-inch pie dish, layer half of the cooked rigatoni pasta on the bottom. Spread half of the ricotta mixture over the pasta, followed by half of the meat sauce. Repeat the layers with the remaining rigatoni, ricotta mixture, and meat sauce.
Top with the remaining mozzarella cheese.
Cover the 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 pasta pie cool for 10 minutes before slicing. Garnish with fresh basil leaves if desired.