01 - Preheat oven to 375°F. Lightly grease a 9x13-inch baking dish.
02 - Boil ziti in salted water until just al dente. Drain and set aside.
03 - Heat olive oil in a skillet over medium heat. Add chopped onion and cook until softened, about 3 minutes.
04 - Stir in minced garlic and cook for 1 minute until fragrant.
05 - Add ground beef, breaking it up with a spoon, and cook until browned, about 6 to 8 minutes. Drain excess fat.
06 - Stir in marinara sauce, dried basil, dried oregano, salt, black pepper, and red pepper flakes if using. Simmer for 5 minutes.
07 - In a large bowl, mix cooked ziti, meat sauce, ricotta, and half of the mozzarella and Parmesan until well combined.
08 - Spread half of the pasta mixture into the prepared dish. Top with half of the remaining mozzarella and Parmesan cheeses.
09 - Add the remaining pasta mixture, then sprinkle with the remaining mozzarella and Parmesan cheeses.
10 - Cover with foil and bake for 20 minutes.
11 - Remove foil and bake an additional 10 to 15 minutes until cheese is melted and golden brown.
12 - Allow to rest for 10 minutes before serving.