Forum Moderators: phranque

Message Too Old, No Replies

htaccess multi language

         

Sandro87

1:33 pm on Jun 1, 2009 (gmt 0)

10+ Year Member



Hello,
I need some advices. I'm planning to make a site with 2 languages and more all with mysql e php combined to work to get the right content in the database to show. I was thinking that maybe was "elegant" and friendly instead of playing with a cookie or IP to get the language I could use subdomains like en.site.com, fr.site.com. The problem is that I don't know how to do it with my code, for what I know subdomains must exist in the server in order to work (I can't create false links with htaccess) right? anyways if you do create them they will be technically sub-directors. But my content is not divided or stored in directories for every language, I just have the content in different columns in the database entries, the files are all in the root.
So what I need practically is to send a $_GET language value according to what X is in X.site.com in order to know what language to use in the functions and to redirect people so they can't just see www.site.com

What's the most common way to do this?
For example, almost every company has a multi language page that will redirect you according to your country. In that case I think it's different they should using aliases or something like that.

Thank you.

[edited by: Sandro87 at 1:36 pm (utc) on June 1, 2009]

jdMorgan

2:18 pm on Jun 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Subdomains must be defined in your DNS zone file, and your server must also 'recognize' them. On servers with unique IP addresses (i.e. IP-based virtual servers), this is trivial: Add the the subdomain(s) (or a wild-card) to the DNS zone file, and then set up some simple handling (e.g. mod_rewrite) on the server.

On name-based virtual servers it's not so easy. In most cases, the host will (by default) force you to define separate subdirectories for the "add-on domains" and this makes 'sharing' scripts and files between the subdomains difficult. In this case, it's usually easier to use explicit subdirectories to specify language instead of trying to use subdomains -- e.g. use example.com/en/ and example.com/de/ instead of en.example.com and de.example.com.

The other option is to upgrade to an IP-based virtual server. It the U.S., this typically costs $1/month.

Jim

Sandro87

5:45 pm on Jun 1, 2009 (gmt 0)

10+ Year Member



I thought so, I'll definitely go with site.com/en/ then.

Thank you a lot.