<?php

ob_start();
$lg = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); // Kullanıcının dilini çektik :)



$path = $_SERVER['REQUEST_URI'];
$dirs = explode('/', $path);
$last_dir = $dirs[count($dirs) - 2];
echo $last_dir; // four

 // Kullanıcı farklı bir dile mensup ise bunu otomatik olarak türkçe dil destekli sayfamıza yönlendiriyoruz.
 if (($lg != 'tr') and ($lg != 'en')) {
	
	if(($last_dir != 'tr') and ($last_dir != 'en')){
	 
	$git = "http://www.siteniz.com/index.php/en/";
    header("Location: $git");

	 }
 
 }else { // Bizim desteklediğimiz dillerden biri ile bağlanmışsa o zaman diline göre yönlendiriyoruz.
 	if(($last_dir != 'tr') and ($last_dir != 'en')){
	 
	 $git = "http://www.siteniz.com/index.php/".$lg."/";
 	 header("Location: $git");
	 }
 }
?>