简体   繁体   中英

Why is “www.example.com” not the same as “example.com”?

I have a website. If I login in the domain of this format http://example.com and then change my address to http://www.example.com , i find my account is not logged in. If I change the address to http://example.com , I find my account is logged in.

I contacted my host, they told me its a programming issue.

How can i solve this issue so both addresses represent same access/session/cookies?

I'm using PHP & MySQL

www.example.com and example.com are two different domains as far as the browser is concerned, apparently, even though they both direct to the same site. Same would happen if you parked a different domain there, say, example.net .

In order to solve the issue, it is rather common to rewrite the URL via .htaccess. Decide upon which domain name you prefer to use and add something like this to your .htaccess:

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

or

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

(the first one removes, the second one adds the www)

How can i solve this issue so both addresses represent same access/session/cookies?

You have to set the domain path of your cookie like this to make it available on all subdomains: (www is a subdomain):

.domain.com

它不一样..通常只需将example.com写入您的浏览器即可访问www.example.com,但您的浏览器会将www添加到您的网址..所以基本上它不一样

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM