Skip to content

Instantly share code, notes, and snippets.

@pvorb
Created July 19, 2010 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvorb/481327 to your computer and use it in GitHub Desktop.
Save pvorb/481327 to your computer and use it in GitHub Desktop.
<?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);
@pvorb
Copy link
Author

pvorb commented Jul 19, 2010

Removed some parts for the sake of simplicity.

@pvorb
Copy link
Author

pvorb commented Jul 19, 2010

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