Skip to content

Instantly share code, notes, and snippets.

@sagikazarmark
Created April 14, 2015 19:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagikazarmark/d262ba75c17061a41d1e to your computer and use it in GitHub Desktop.
Save sagikazarmark/d262ba75c17061a41d1e to your computer and use it in GitHub Desktop.
PHP server router script
<?php
/**
* PHP Server router script
*/
// determine the file we're loading, we need to strip the query string for that
if (isset($_SERVER['SCRIPT_NAME']))
{
$file = $_SERVER['DOCUMENT_ROOT'].$_SERVER['SCRIPT_NAME'];
}
else
{
$file = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'];
if (($pos = strpos($file, '?')) !== false)
{
$file = substr($file, 0, $pos);
}
}
if (file_exists($file))
{
// bypass existing file processing
return false;
}
else
{
// route requests though the normal path
include($_SERVER['SCRIPT_NAME'] = $_SERVER['DOCUMENT_ROOT'].'/index.php');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment