Load language according to site URL

Hi all,

I’m creating a site that will be available in both Dutch and French. The client has provided us with both “somedutchdomain.com” and “somefrenchdomain.com” and wants the visitor to see either version of the site according to the domain name they used to reach the site.

I was wondering whether there was a way to do this using if/else statements, something in the line of “if domain is somedutchdomain.com, show /nl; if domain is somefrenchdomain.com, show /fr”

Thanks in advance for your suggestions

This is untested but should point you in the right direction:


//Check here for www. and remove it
$_SERVER['HTTP_HOST'] = str_replace('www.', '', $_SERVER['HTTP_HOST']);

//Check the domain
switch($_SERVER['HTTP_HOST'])
   {
   case: 'french.com':
      //Load french language here
      break;
   case: 'dutch.com':
      //Load dutch language here
      break;
   default:
      //Load default language here
      break;
   }

Okay, thanks. Think this would work?


<?php
//Check here for www. and remove it
$_SERVER['HTTP_HOST'] = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$page  = $_SERVER['REQUEST_URI'];

//Check the domain
switch($_SERVER['HTTP_HOST'])
   {
   case: 'french.com':
      header("Location: /fr/$page");
      break;
   case: 'dutch.com':
      header("Location: /nl/$page");
      break;
   default:
      header("Location: /nl/$page");
      break;
   } 
?>

note: Sorry, unable to test at the moment, both domains have been set up just an hour ago, so they are not available to browse yet.

Should do :wink:

Mmmm.

Got around to testing this, but the page show up empty with this code in the header. Looks like some parse error…