Preheat oven to 400°F. Lightly grease a 9x13 inch baking dish with butter or cooking spray.
Layer half of the potato slices in the bottom of the dish, slightly overlapping. Scatter half of the onion rings over the potatoes. Season lightly with salt and pepper. Repeat with remaining potatoes and onions, seasoning again.
Melt butter in a medium saucepan over medium heat. Whisk in flour and 1/2 tsp salt. Whisk constantly for 1 minute.
Pour in milk slowly while whisking continuously. Cook, stirring frequently, until the sauce thickens and begins to bubble.
Stir in 1 cup of the shredded cheddar cheese. Keep stirring until the cheese melts completely and the sauce is smooth.
Pour the cheese sauce evenly over the layered potatoes and onions. Use a spoon to ensure sauce gets into all gaps.
Cover the dish tightly with aluminum foil. Bake for 45 minutes.
Remove foil and sprinkle remaining 1/2 cup cheddar cheese over the top. Bake uncovered for 35 to 45 minutes, until potatoes are fork-tender and top is golden brown.
Broil for 3 to 4 minutes if you want a darker, crispier top. Watch closely to prevent burning.
Rest for 15 to 20 minutes before serving to allow sauce to thicken.