1 个网站的 2 个 IP 地址

发布于 2024-08-16 05:54:21 字数 393 浏览 4 评论 0原文

我有一个完全是法语的网站。我计划从几个月开始就有一个英文版本。一切工作正常,人们可以切换他们的语言,会话可以处理他们的语言。

问题是,现在我购买了一个与法国域名不同的域名,我想它需要指向主机的相同子域名。

我想我需要编写一些代码来检查域名,以及用户是否使用英语访问服务器,以将会话切换到英语,否则使用法语。 我是否错了?

我想我会这样做,但网站的许多其他部分可能完全不同,例如广告和图像。 处理多语言网站的最佳方法是对这些广告和图像的语言进行多次比较吗?或者在其他子域上复制该网站并将新域链接到新文件夹(我真的认为从长远来看,复制将是最糟糕的)。

任何建议将不胜感激。

(此问题中的两个问题均以粗体显示)

I have a website that is totally in French. I plan to have an english version since few months. Everything work fine, people can switch their language and the session handle their language.

The problematic is that now I have bought a domain that is different of the french one and I guess it will require to point to the same sub-domain of the host.

I guess that I will need to make some code to check the domain name and if the user is coming to the server with the english one to switch the session to the english language otherwise to use the french language. Am I wrong or not?

I think I will proceed that way but many other part of the website might be completly different like Ads and Images. Is the best way to handle multilanguage website is to make many comparison of the language for these Ads and Images? or to make a duplicate of the website on an other sub-domain and link the new domain to the new folder (I really think that duplicating will be worst for the long run).

Any advice would be appreaciate.

(Both questions in this question are bolded)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

是你 2024-08-23 05:54:21

如果您的意思是一个新域名,请将其指向与您的第一个域相同的服务器,并在 PHP 脚本中进行语言检查(或任何需要的操作):

if ($_SERVER["HTTP_HOST"] == "my_first_domain_name.fr")
 { // use french site }
elseif ($_SERVER["HTTP_HOST"] == "my_second_domain_name.fr")
 { // use english site }

您还可以考虑将法语内容拆分为一个解决方案目录名为/fr,英文内容位于/en

If what you mean is a new domain name, point it to the same server as your first domain, and do the language checking (or whatever is required) in the PHP script:

if ($_SERVER["HTTP_HOST"] == "my_first_domain_name.fr")
 { // use french site }
elseif ($_SERVER["HTTP_HOST"] == "my_second_domain_name.fr")
 { // use english site }

you could also think about a solution that splits french content into a directory named /fr, and english content in /en.

小巷里的女流氓 2024-08-23 05:54:21

我构建的支持多种语言的每个站点都会检测用户的语言,然后将其存储在会话信息中。如何检测他们的语言取决于您(根据他们的 IP、默认语言等),但请确保为用户提供更改语言的简单方法。然后,根据会话信息,我们将更新网站副本(即,提供不同的翻译)、体验(例如,仅显示该地区的产品或新闻报道)等

。不同的[子]域是一个可行的选择,尽管我不喜欢:您必须支持并发布到所有这些不同的域。

如果用户来自您的新域,您还可以设置会话变量。只需让两个域都指向同一个地方即可。

Every site that I have built to support multiple languages detected the user's language and then stored it in their session information. How you detect their language is up to you (from their IP, defaulting to a language, etc.), but make sure you provide the user an easy way to change languages. Then, based on the session information, we would update the site copy (ie., put up a different translation), experience (ex., only show products or news stories from that locale), etc.

Having multiple copies of the site on different [sub-]domains is a viable option, though one I don't like: you will have to support and release to all those different domains.

You could also set the session variable if the user comes from your new domain. Just have both domains point to the same place.

携余温的黄昏 2024-08-23 05:54:21

您的目标应该是尽可能少地重复。重复您的站点将导致将来的可维护性问题。

您可以将两个域名指向同一服务器 IP,并使用条件服务器端代码来确定向用户提供哪些内容。

在 PHP 中,变量 $_SERVER['SERVER_NAME'] 填充有来自客户端 http 请求的服务器名称(例如“google.com”)。

如果人们通过不同的域名访问相同的php脚本,您可以使用该值来决定呈现哪些内容(例如,有一个html模板,根据站点从数据库填充相关内容)。

在广告方面,你也可以这样做。像谷歌广告这样的东西可能会为你解决这个问题。

更一般地说,我们在这里讨论虚拟主机。有很多不同的方法可以实现您想要的目标,并且方法会根据问题的具体情况、平台、托管限制等而有所不同。

许多网站将默认语言选择(以及广告、使用的货币等)基于 < a href="http://geo-ip.indbuzz.com/" rel="nofollow noreferrer">geoip,回退到某些默认值。

You should aim to duplicate as little as possible.. duplicating your site will lead to maintainability problems in future.

You can point both domain names at the same server IP, and have conditional server-side code to determine which content is served to the user.

In PHP, the variable $_SERVER['SERVER_NAME'] is populated with the server name from the client's http request (e.g. 'google.com').

If people access the same php script via different domain names, you could use the value of this to decide which content to present (e.g. have an html template, with the relevant content populated from the database according to site).

In terms of advertisements, you could do the same. Something like google ads will likely take care of this for you.

More generally, we're talking about virtualhosts here. There are lots of different ways to achieve what you're after, and methods vary according to the specifics of the problem, platform, hosting constraints etc.

A lot of sites base the default language choice (and advertisements, currencies used etc) on geoip, falling back to some default.

寂寞美少年 2024-08-23 05:54:21

切这种饼干的方法有很多种。请注意,由于会话由 cookie 控制(至少默认情况下),因此您的用户将根据他们请求的域获得不同的会话。

There are a lot of ways to cut this cookie. Note that since sessions are controlled by cookies (by default at least), your users will get different sessions depending on which domain they request.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文