Created
July 19, 2010 12:22
-
-
Save pvorb/481327 to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* This file grabs requested html files. | |
* | |
* @author Paul Vorbach <vorbach@genitis.org> | |
* @license http://opensource.org/licenses/mit-license.php MIT License | |
* @version 0.1.0 | |
* @package org.genitis.yuki | |
*/ | |
// Set <code>$_GET['q']</code> as <code>$path</code>, default is | |
// <code>''</code>. | |
$path = ''; | |
if (isset($_GET['q'])) { | |
$path = $_GET['q']; | |
unset($_GET['q']); | |
} | |
// Set <code>$content</code> and <code>$index</code> | |
if ($path == '') { | |
$content = '.'; | |
$index = 'index'; | |
} elseif (strrpos($path, 'index/')) { | |
// Redirect to a 404 error, no content file has been found | |
require_once '../lib/functions.php'; | |
redirect(404, 'error/404/', $path); | |
} else { | |
$content = $path; | |
$index = $content.'index'; | |
$content = rtrim($content, '/'); // remove trailing slash | |
} | |
$content_path = $content.'.html'; | |
$index_path = $index.'.html'; | |
// Try to include the file <em>path/to/file.html</em> first. | |
// Then try to include <em>path/to/file/index.html</em>. | |
if (file_exists($content_path)) { | |
include $content_path; | |
exit; | |
} elseif (file_exists($index_path)) { | |
include $index_path; | |
exit; | |
} | |
// Redirections | |
include '../lib/redirections.php'; | |
require_once '../lib/functions.php'; | |
if (isset($redirections[$path])) | |
redirect(301, $redirections[$path]); | |
// Redirect to a 404 error, no content file has been found | |
redirect(404, 'error/404/', $path); |
Between the include $…_path;
and exit;
statements you may save back your page visits or something like that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Removed some parts for the sake of simplicity.