Forum Moderators: phranque
I have two domains:
www.1234.com
www.1234x.com
The "x.com" is basically a domain pointer, i.e., they are exactly the same domain. The pointing is defined in the httpd.conf file (I think, because I use cpanel to define this link)
My problem with cookies is two-fold:
1. When a user sets a cookie from www.1234.com, it does not show up on 1234.com (without the "www"). To do this, I was wondering if it is a good idea to rewrite URL and force the user into the domain without the "Www". e.g.,
RewriteCond %{HTTP_HOST} ^www\.1234\.com$
RewriteRule ^(.+) %1234\.com$1 [C]
Problem is, this doesn't really work as desired. Would appreciate if someone can help me refine this code above? Thanks!
2. Secondly, a cookie set on 1234.com is not valid on 1234x.com. How can I get around this? Any workarounds that you have used?
Thanks!
RewriteCond %{HTTP_HOST} ^www\.1234\.com
RewriteRule (.*) http://1234\.com/$1 [R=301,L]
There is no way around this that will work reliably. Cross-domain cookies would be a major security problem, so cookies are defined to be per-domain.
The best way to cure all your troubles is to redirect all of your domains and domain variants (www vs. no-www) to a single domain, then set the cookies from there. Either that, or set up all of your domains as truly-separate sites, and let them set and test their own unique cookies.
Jim