How to have a multilingual welcome on your website!

If you would like to welcome visitors to your own website, by directing visitors based on their prefered language, this is how I do it.

The technology is PHP, which is a simple language that adds a level of capability and dynamic that you can't have with Javascript and HTML. Obviously you need access to PHP. Most hosts do provide it.. but this is one step beyond Geocities. If your host doesn't offer PHP.. maybe get one that does - it's not expensive.

The script below simply redirects incoming requests to pages associated with the first two letters of the code in the language preference of the visitors browser settings.

The two files you need are index.txt and fish-config.txt

Download these text files by right-clicking the links and choosing save-as. Rename the first 'index.html' and the second 'fish-config.php'.

The index.html is the root index file you'll likely recognise. This doesn't actually do any more than redirect requests to files listed in the config file. fish-config.php is a file that index includes when it is run. i.e. you need PHP includes enabled, and to put this file in the PHP includes folder.

The script is an improved version of one I found on the net years ago. It has better security and handles more variety of input from browsers language preference.. stripping the dialects to find the core language.. it can also now handle upto 100 languages. Don't try changing it unless you are confident in PHP, you can open holes in security with badly coded PHP.

Four things to do..

  1. fish-config.php - add lines to as needed but adjust the $count variable, keeping it one above the last array record number.
  2. fish-config.php & index.html - change the http://www.example.com/ to reflect your own site.
  3. index.html - Change line 40 $redirect = 'babel/index.html'; to suggest the location of a default file.. for when someone doesn't have a language preference in the get request.
  4. index.html - Change line 35 $redirect = 'error/bad-request.html'; to suggest the location of your error file for HTTP code 400 Bad Request

That's about it..

You can find the codes for languages on The ISO639-1 language code list

Good luck.. any problems let me know.