In a old site, I was changing the way that CustomErrors works by adding redirectMode=\"ResponseRewrite\" (new in 3.5 SP1):
redirectMode=\"ResponseRewrite\"
I found that the problem was in Error.aspx. Still can't find what was the actual error in error.aspx that causes the problem.
Changing the page to a static html file solved the problem.