Preheat oven to 375°F (190°C).
- Cook ziti in salted water until al dente. Drain and set aside.
- Heat olive oil in a skillet over medium heat. Add onion and sauté until soft. Add garlic and cook for another minute.
- Add ground beef or sausage (if using) and cook until browned. Drain fat.
- Stir in marinara sauce, Italian seasoning, salt, and pepper. Simmer for 5–10 minutes.
- In a bowl, mix ricotta cheese with egg (if using), 1/4 cup Parmesan, salt, and pepper.
- In a large bowl, mix cooked pasta with half of the meat sauce and a handful of mozzarella.
- Spread a layer of meat sauce in the bottom of a greased 9×13-inch baking dish.
- Add half the pasta mixture, then dollop ricotta mixture evenly over it.
- Add the rest of the pasta, top with remaining sauce, mozzarella, and Parmesan.
- Cover with foil and bake for 25 minutes. Remove foil and bake for another 10–15 minutes, until cheese is golden and bubbly.
- Let rest for 5–10 minutes. Garnish with fresh basil or parsley if desired.