为什么是“www.example.com"与“example.com"不一样? [英] Why is "www.example.com" not the same as "example.com"?

查看:37
本文介绍了为什么是“www.example.com"与“example.com"不一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站.如果我在此格式的域中登录 http://example.com 然后将我的地址更改为 http://www.example.com,我发现我的帐户没有登录.如果我将地址更改为 http://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.

如何解决这个问题,让两个地址代表相同的访问/会话/cookies?

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

我正在使用 PHP &MySQL

I'm using PHP & MySQL

推荐答案

www.example.comexample.com 就浏览器而言是两个不同的域显然,即使他们都指向同一个站点.如果您将不同的域停放在那里,例如 example.net,也会发生同样的情况.

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.

为了解决这个问题,通过 .htaccess 重写 URL 是很常见的.决定您更喜欢使用哪个域名,然后将类似的内容添加到您的 .htaccess 中:

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]

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

(第一个删除,第二个添加www)

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

这篇关于为什么是“www.example.com"与“example.com"不一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆