01 - Preheat oven to 375°F. Lightly grease a 9x13-inch baking dish.
02 - Boil ziti in salted water until just al dente, then drain and set aside.
03 - Heat olive oil in a skillet over medium heat. Add 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. Cook until browned, 6 to 8 minutes, then drain excess fat.
06 - Mix marinara sauce with basil, oregano, salt, black pepper, and red pepper flakes if used. Simmer for 5 minutes.
07 - In a large bowl, combine cooked ziti, meat sauce, ricotta, and half of the mozzarella and Parmesan. Stir until evenly blended.
08 - Spread half of the pasta mixture in the baking dish. Top with half of the remaining mozzarella and Parmesan cheeses.
09 - Add the remaining pasta mixture, then sprinkle with the rest of the mozzarella and Parmesan cheeses.
10 - Cover with foil and bake for 20 minutes.
11 - Remove foil and continue baking for 10 to 15 minutes until cheese is melted and golden on top.
12 - Let the dish rest for 10 minutes to set before serving.