Created
September 27, 2011 15:34
-
-
Save jlongster/1245398 to your computer and use it in GitHub Desktop.
PHP MADNESS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url_parts = explode('/', trim($_SERVER['REDIRECT_URL'], '/')); | |
if ($url_parts[0] != $lang) { | |
// Bug 619404 Quickly redirect homepage | |
if ($_SERVER['REQUEST_URI'] == '/') { | |
$_SERVER['REQUEST_URI'] = '/firefox/'; | |
} | |
$parsed_url = parse_url($_SERVER['REQUEST_URI']); | |
// This matches both / and /firefox because of the above code | |
if (rtrim($parsed_url['path'], '/') == '/firefox') { | |
$is_mobile_redirected = FALSE; | |
$ua = $_SERVER['HTTP_USER_AGENT']; | |
$ua_nocase = strtolower($ua); | |
// Redirect mobile devices (Android, Maemo) | |
if (preg_match(':(Android|Maemo|Fennec|Linux armv7l):', $ua)) { | |
if (isset($_GET['mobile_no_redirect']) || isset($_COOKIE['mobile_no_redirect'])) { | |
setcookie('mobile_no_redirect', '1', 0, '/'); | |
} else { | |
$_SERVER['REQUEST_URI'] = '/m/'; | |
$is_mobile_redirected = TRUE; | |
} | |
} | |
// Same with iOS devices | |
if (strpos($ua_nocase, 'iphone') !== FALSE && | |
strpos($ua_nocase, 'ipad') === FALSE) { | |
if (isset($_GET['mobile_no_redirect']) || isset($_COOKIE['mobile_no_redirect'])) { | |
setcookie('mobile_no_redirect', '1', 0, '/'); | |
} else { | |
$_SERVER['REQUEST_URI'] = '/m/ios'; | |
$is_mobile_redirected = TRUE; | |
} | |
} | |
if (!$is_mobile_redirected) { | |
// Bug 629407 Redirect to user-specific pages | |
// This is also implemented in .htaccess, but we do it here | |
// to redirect the user only once | |
if (preg_match('/Firefox\/(7|8|9|10)/', $ua)) { | |
$_SERVER['REQUEST_URI'] = '/firefox/fx/'; | |
} | |
else { | |
$_SERVER['REQUEST_URI'] = '/firefox/new/'; | |
} | |
} | |
if (isset($parsed_url['query']) && $parsed_url['query'] !== '') { | |
$_SERVER['REQUEST_URI'] .= '?' . $parsed_url['query']; | |
} | |
} | |
header( "HTTP/1.1 301 Moved Permanently" ); | |
header("Location: {$config['url_scheme']}://{$config['server_name']}/{$lang}{$_SERVER['REQUEST_URI']}"); | |
header('Pragma: no-cache'); | |
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, private'); | |
header("Vary: User-Agent, Accept-Language"); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment