The reason for this is that cookies does not work on different domains. So if you want to use both domain.com and www.domain.com you should use relative url's in your links, this should solve the problem. Then the user will always to linked to the current domain.