Jump to content
xisto Community
miCRoSCoPiC^eaRthLinG

Redirecting From Landing Page Of A Php+mysql Multilingual Site?

Recommended Posts

Hey guys! I'm designing this multi-lingual site with php + mysql. I'm using a 2 letter language code following the domain name to identify the language the content is delivered in. For example,

domain.com/en/ - English

domain.com/th/ - Thai and so on...

 

All URLs (am utilizing mod_rewrite) take the general form, http://forums.xisto.com/no_longer_exists/Here's my problem scenario: When person A visits the site by keying in http://forums.xisto.com/no_longer_exists/, I can directly serve the pages in the desired language. If person A keys in just http://www.domain.com/ (without any language code), I redirect to the english page by default - but I'm in a dilemma as to what redirection header to serve for this URL. I had read about a '300 Multiple Choice" header and that's what I have implemented experimentally. Here's the code:


header( 'HTTP/1.1 300 Multiple Choices' );header( 'Location: ' . DOMAIN . '/en' );

Is this the correct way to do it? I had thought of using a 301 earlier on - but that didn't strike quite right. Has anyone worked on such a case and can throw some light on this? Thanks, m^e P.S. And don't gawk at me :o Been keeping ultra-busy doin' some hardcore php!


Share this post


Link to post
Share on other sites

Hey m^e,I think you're looking at this the wrong way, people should not have to key in the information for what language they want.One way is we could use content negotiation based on users preferences, which is based entirely on the server communicating with the client (web browser) and selecting the appropriate content, based on their preference. There can be some changes to how this originally works with Apache, in which we can use server-side languages to intercept and generate the appropriate content.By the way, Header 300 would be correct if you used content negotiation like above, otherwise, you're not really giving the user/user-agent a choice.Cheers,MC

Share this post


Link to post
Share on other sites

Aha MC :o Long time....

One way is we could use content negotiation based on users preferences, which is based entirely on the server communicating with the client (web browser) and selecting the appropriate content, based on their preference. There can be some changes to how this originally works with Apache, in which we can use server-side languages to intercept and generate the appropriate content.

Yup! For content negotiation I'm relying mostly on cookies and sessions... if either are found, the site redirs to a particular lang version automatically... That part is taken care of.

However, it's the redirection issue - for people who arrive at the primary domain - that's got me a little baffled..

It's not a 301 for sure, coz that would imply xxx.com = xxx.com/en (in my case). to a search engine crawler... which is not quite correct, if you know what I mean!

Studying the different header types - 300 seems to be the only logical choice, but I didn't manage to find any hands-on (code) examples of implementation. So am kind of unsure if I'm doing it right!

Good to see you around :o

Cheers,
m^e

Share this post


Link to post
Share on other sites

Google most likely does it using the combination of cookies and a Geo-IP service.

 

First when you type Google.com and your browser doesn't contain any cookies set by them, the redirection occurs according to your IP (ISP) location and the cookie for the same is set in your browser.

 

If you set the google domain for another language as your preferred one, the cookie is altered accordingly.

 

Next visit onwards you are auto-redirected based on the cookie.

 

I'm following a similar model here - and you've brought up a good point. Maybe I should try analyzing the headers and see how they're performing the redirection.

 

Thanks,

m^e

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.