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"],"/"); $uri=trim($_SERVER["REQUEST_URI"],"/");
// auto lang redirect: $lang="en";
if (!$uri) { if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
$lang="en";
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
$l=substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2); $l=substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2);
if (isset($otherlang[$l])) { if (isset($otherlang[$l])) {
$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,9 +51,13 @@ 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")) {
header("HTTP/1.0 404 Not Found"); if (file_exists("../pages/".ucfirst($uri)."-".$lang.".md")) {
echo "<h1>File not found</h1>"; header("Location: /".ucfirst($uri)."-".$lang);
exit(); exit();
}
header("HTTP/1.0 404 Not Found");
echo "<h1>File not found</h1>";
exit();
} }
// automatic compilation / caching of HTML pages // automatic compilation / caching of HTML pages