How to fix an infinite 301 redirect loop in WordPress

I just ran into this problem today; thought I should post the solution in case anybody else finds themselves in the same boat.

I moved a WordPress blog from one server to another which was running lighttpd with a blanket 301 redirect to from www to non-www URLs. When I fired up a browser to test it, I got the dreaded “this website is responding in a way that will never resolve” message. A quick look at the lighttpd logs confirmed that I was bouncing from www.example.com to example.com then back to www.example.com.

I expected ...

more ...