Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Www and non www sites

Tags:

php

cakephp

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.

like image 797
madhu Avatar asked Oct 28 '10 11:10

madhu


2 Answers

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]
like image 156
Alex Rashkov Avatar answered Sep 21 '22 14:09

Alex Rashkov


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

like image 32
DBlackborough Avatar answered Sep 20 '22 14:09

DBlackborough