Preheat and prep: Heat the oven to 375°F (190°C).
Lightly grease a 9x13-inch baking dish with cooking spray or olive oil.
Cook the pasta: Bring a large pot of salted water to a boil. Cook pasta until just shy of al dente (about 1–2 minutes less than package directions). Drain and set aside.
Sauté aromatics: In a large skillet, heat olive oil over medium heat.
Add onion and cook until soft and translucent, 4–5 minutes. Stir in garlic and cook 30 seconds, until fragrant.
Build the sauce: Add marinara or pizza sauce, Italian seasoning, red pepper flakes (if using), salt, and black pepper. Simmer 3–4 minutes to meld flavors.
Taste and adjust seasoning.
Combine pasta and sauce: In a large bowl, toss the cooked pasta with the sauce. Fold in 1 cup mozzarella and 1/4 cup Parmesan.
Add ricotta: Dollop ricotta throughout the pasta mixture and gently fold to create creamy pockets. Don’t overmix; those pockets make great texture.
Assemble the bake: Spread half the pasta into the prepared baking dish.
Sprinkle with a layer of pepperoni slices, then add the remaining pasta on top.
Top with cheese and pepperoni: Sprinkle the remaining 1 cup mozzarella and 1/4 cup Parmesan over the pasta. Arrange more pepperoni on top for that classic pizza look.
Bake: Cover loosely with foil and bake for 15 minutes. Remove foil and bake another 10–12 minutes, until the cheese is melted and bubbling around the edges.
Optional broil: Broil for 1–2 minutes to crisp the pepperoni and brown the cheese.
Watch closely to prevent burning.
Rest and garnish: Let the pasta bake rest 5 minutes to set. Sprinkle with chopped basil or parsley before serving.