From e2a3726ad1a9207b0714f1e902944c40c0bb097e Mon Sep 17 00:00:00 2001 From: alternc Date: Wed, 3 Feb 2016 21:31:54 +0100 Subject: [PATCH] fixing router.php for nginx & better handling of fancy urls --- doc/www/router.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/doc/www/router.php b/doc/www/router.php index 448cc0f0..29438966 100644 --- a/doc/www/router.php +++ b/doc/www/router.php @@ -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; + $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,9 +51,13 @@ unset($otherlang[$lang]); header("Content-Type: text/html; charset=UTF-8"); if (!file_exists("../pages/".$uri."-".$lang.".md")) { - header("HTTP/1.0 404 Not Found"); - echo "

File not found

"; - exit(); + if (file_exists("../pages/".ucfirst($uri)."-".$lang.".md")) { + header("Location: /".ucfirst($uri)."-".$lang); + exit(); + } + header("HTTP/1.0 404 Not Found"); + echo "

File not found

"; + exit(); } // automatic compilation / caching of HTML pages