fixing router.php for nginx & better handling of fancy urls

This commit is contained in:
alternc 2016-02-03 21:31:54 +01:00
parent d45c1d8384
commit e2a3726ad1
1 changed files with 17 additions and 9 deletions

View File

@ -11,15 +11,16 @@ $locales=array("fr" => "fr_FR.UTF-8",
$uri=trim($_SERVER["REQUEST_URI"],"/");
// auto lang redirect:
if (!$uri) {
$lang="en";
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
$lang="en";
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
$l=substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2);
if (isset($otherlang[$l])) {
$lang=$l;
}
}
}
// auto lang redirect:
if (!$uri) {
header("Location: /Home-".$lang."");
exit();
}
@ -27,6 +28,9 @@ if (!$uri) {
if (preg_match('#^(.*)-([^-]*)$#',$uri,$mat)) {
$lang=$mat[2];
$uri=$mat[1];
} else {
header("Location: /".$uri."-".$lang);
exit();
}
if (!isset($otherlang[$lang])) {
@ -47,6 +51,10 @@ unset($otherlang[$lang]);
header("Content-Type: text/html; charset=UTF-8");
if (!file_exists("../pages/".$uri."-".$lang.".md")) {
if (file_exists("../pages/".ucfirst($uri)."-".$lang.".md")) {
header("Location: /".ucfirst($uri)."-".$lang);
exit();
}
header("HTTP/1.0 404 Not Found");
echo "<h1>File not found</h1>";
exit();