Http host / cookie problem?

Hi

I’ve just registered a domain for my site and have noticed that it sets different cookies depending on whether you have www in front of the url or not
ie I can be logged on as two different users in the same browser, the one logged into www.mysite.com and the other into mysite.com

I had a look around and most sites seem to automatically put a www in front even if you type site.com into the address bar.

So i just put a little function at the top of the page to check whether a www is present in the address and if not then redirect accordingly. Is this normal or do i have a problem somewhere along the line?

Thanks!

yes what you have done is OK.

strictly speaking a dns name should have a host (ie www) included but lots of isp create an A-record to allow the www or whatever to be omitted.

You can put this in .htaccess rather than a function at the top of the page.


# force http://domain.com
RewriteCond %{HTTP_HOST} ^www\\.domain\\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

# _or_ force http://www.domain.com
RewriteCond %{HTTP_HOST} ^domain\\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

They are different domains, as far as which is correct, I think it’s entirely up to you.

Thanks very much, will get that a try…