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