Www and non www sites

I have a say domain http://www.testexample.com . When I enter http://www.testexample.com and return to http://testexample.com in the browser; registered user information is not displayed.
I know that both of them are treated differently and therefore do not save the session for http://www.testexample.com when accessing http://testexample.com .

Please let me know if cakephp has a way to make a match on TLD. Therefore, whenever I type http://testexample.com , it should go in session for http://www.testexample.com

I use the following code to redirect from one URL to another

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

this is on my local test machine. It works sometimes, and sometimes not.
I also added the rewritelog directive to the httpd.conf file. But the log file is not updated. Please let me know if anyone has any indication of this.

+5
source share
4 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] 
+5
source

Set the domain for the cookie as testexample.com, then it can be available for different domains and also not worry about www.

+4
source

If you have many projects and don’t want to hard-copy your domain name to .htaccess again and again, try this code:

 RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L] 

this redirects non-www to www. While you are using cakephp, put it in your .htaccess, which is located in /webroot

+2
source

Try ini_set('session.cookie_domain', $domain); (registered as ini_set session.cookie_domain and session_set_cookie_params() ), where $ domain is your domain name with a prefix . . So, using the domain example.com (for rfc 2606 ), you should use:

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

Note that this is not CakePHP's special solution - viewing the code for CakeSession , session.cookie_domain never set, which means that it drops to the default value. Filling this line in app/config/bootstrap.php or app/config/core.php should do it for you.

0
source

Source: https://habr.com/ru/post/896114/


All Articles