Skip to content

Instantly share code, notes, and snippets.

@filipekiss
Last active December 15, 2016 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save filipekiss/9178973 to your computer and use it in GitHub Desktop.
Save filipekiss/9178973 to your computer and use it in GitHub Desktop.
A server.php to emulate Apache's mod_rewrite
<?php
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri = urldecode($uri);
$requested = './'.$uri;
//Redirect if no trailing slash is found
if (substr($uri, -1) !== "/" && !stristr($uri, '.')) {
$uri .= "/";
header("Location: ".$uri);
}
if ($uri !== '/' and file_exists($requested))
{
return false;
}
require_once 'index.php';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment