php - Change language directory without redirecting to the index page -
i have site in 3 languages:
www.mysite.com/it/files www.mysite.com/de/files www.mysite.com/fr/files
on header of site have 3 link, 1 each language. each link redirect to
/language/index.php
i'd redirect user current page watching in new language.
i tried with
__file__
or
dirname
but didn't reach that!
thank you!
try in page load:
$prefix = $_server['http_host']; $file = explode('/', $_server['php_self']); $page = $file[count($file)-1]; if (file_exists($prefix.'/it/'.$page)) { http_redirect($prefix.'/it/'.$page); // italian } if (file_exists($prefix.'/de/'.$page)) { http_redirect($prefix.'/de/'.$page); // german } if (file_exists($prefix.'/fr/'.$page)) { http_redirect($prefix.'/fr/'.$page); // french }
in javascript (jquery click example) this:
var host = document.location.hostname; var path = window.location.href; var filename = path.replace(/^.*[\\\/]/, ''); $('.myitalianlink').click(function(){ window.location.href = host + '/it/' + filename; // italian }); console.log(host + '/it/' + filename);
outputs:
http://www.mywebsite.com/it/html4.php
the javascript approach more suiting needs, it's more reactive in case of user interaction (the links named).
Comments
Post a Comment