tags:

views:

111

answers:

3

I have a domain say http://www.testexample.com. When I login to http://www.testexample.com and come back to http://testexample.com in browser; the logged in user information is not displayed.
I know that the both of the above are treated differently and hence it is not retaining the session for http://www.testexample.com while accessing http://testexample.com.

Please let me know if cakephp has a way to do a match on the TLD. So whenever I type http://testexample.com it should take session for http://www.testexample.com

I am using the following code to redirect from one URL to the other

RewriteCond %{HTTPS} off   
RewriteCond %{HTTP_HOST} ps6309 [NC]   
RewriteRule ps6309.domain.co.in [L,R=301]

this is on my local test machine. This works sometimes and sometimes doesn't.
Also I have added the rewritelog directive to my httpd.conf file. But the log file is not getting updated. Please let me know if anyone has any pointers to this.

+3  A: 

Use .htaccess to redirect all http://domain.com -> http://www.domain.com

RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
infinity
u posted first thats y deleted mine :-)
piemesons
I think this is a better solution, because then the user will only use one domain, and the experience will be less confusing (e.g. the visited links would change if he visited two domains). Also, it's better caching, since we will have only one copy of each resource.
Denilson Sá
extactly - serving both urls makes no sense. use 'www' over ''.
mark
+4  A: 

Set the domain for the cookie as testexample.com, then it can be shared across sub domains as well as not worrying about www.

G3D
I am Using Cakephp Auth component for session and the user information is coming from the same. Would it be achieved with cookies then?
madhu
Even though you are using sessions a cookie is still created so that the user can be matched to the session file (or table) on the server. I don't know Cake, never used it but check this out, might point you in the right direction. http://kodegeek.wordpress.com/tag/cakephp/
G3D
A: 

Try ini_set('session.cookie_domain', $domain); (documented as ini_set session.cookie_domain and session_set_cookie_params()), where $domain is your domain name prefixed by a .. So, using the domain example.com (per rfc 2606), you'd use:

ini_set('session.cookie_domain', '.example.com');

Please note that this is not a CakePHP specific solution - looking at the code for CakeSession, session.cookie_domain is never set, meaning that it falls to it's default value. Stuffing that line in your app/config/bootstrap.php or app/config/core.php should do it for you.

michaelc