I want to redirect a direct access to the website to its English content. Do you see any problem or improvement of my code?
/*
* Load English page if *.com domain
*/
$domain = $_SERVER['SERVER_NAME'];
$extension = pathinfo($domain, PATHINFO_EXTENSION);
if($extension == "com" &&
!preg_match('/'.$domain.'/', $_SERVER['HTTP_REFERER']) &&
$_SERVER['REQUEST_URI'] == '/'){
header('Location: /en/');
exit;
}
One problem I see is that if the users browser has HTTP_REFERER
deactivated he couldn't access to http://domain.com
. Is there a better solution?
Here example of the usage:
http://domain.com
should be forwarded to http://domain.com/en/
<a href='/'>home</a>
or <a href='http://domain.com'>home</a>
it should not be redirected.