views:

207

answers:

4

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)

+1  A: 

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.

Sam Bisbee
Should I check the URL and change the Session or if the user switch is language redirect him automaticly to the good URL?
Daok
I'd detect the URL (ex., en.example.com), set the session variable, and then redirect to the actual domain (ex., www.example.com). No actual content is at the locale subdomain, it's just used to switch.Your locale switching menu is then just a list of links to subdomains (en.example.com, fr.example.com, etc.). You could apply the language switch to any URL request that isn't for the www subdomain (assuming you're forwarding example.com to www.example.com). If you don't recognize the subdomain, then forward to your default language.
Sam Bisbee
+2  A: 

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.

Pekka
+1  A: 

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.

actually, $_SERVER['HTTP_HOST'] might be a better bet than $_SERVER['SERVER_NAME'], for reasons pointed out here: http://shiflett.org/blog/2006/mar/server-name-versus-http-host
A: 

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.

troelskn