Preheat oven to 275°F (135°C). Pat the rack of ribs dry with paper towels and remove the silvery membrane from the bone side.
In a small bowl, whisk together brown sugar, smoked paprika, garlic powder, onion powder, salt, black pepper, and cayenne pepper (optional).
Generously rub the spice mixture on both sides of the ribs, pressing gently to adhere.
Tear off a large piece of heavy-duty aluminum foil. Place ribs meat-side up on the foil and pour apple cider vinegar (or water) over them.
Tightly wrap the ribs in the foil, sealing all edges. Place wrapped ribs on a baking sheet and bake for 2.5–3 hours for baby back ribs (3–3.5 hours for spare ribs), until very tender.
Carefully open the foil packet and drain any accumulated liquid. Increase oven temperature to 375°F (190°C).
Brush BBQ sauce all over the ribs. Return ribs to the oven, uncovered, and bake for 20–30 minutes, brushing with more sauce halfway through, until sauce is bubbly and caramelized.
Remove ribs and let rest on a cutting board for 10–15 minutes. Slice between the bones and serve.