Put "ReturnHeaders" into your script just prior to the
ns_returnredirect and then you'll be able to see the headers
returned. Look at the Location: header to see what path you are
being redirected to.
Personally I've hacked ns_returnredirect on my server to use the
name sent with the Host: header instead of whatever hostname the
server thinks it should use.