Skip to content

Instantly share code, notes, and snippets.

@scribu
Forked from tamagokun/router.php
Created November 16, 2012 15:32
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scribu/4088244 to your computer and use it in GitHub Desktop.
Save scribu/4088244 to your computer and use it in GitHub Desktop.
Run a Wordpress site via PHP's built-in web server
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
chdir( $root );
$path = '/'.ltrim( parse_url( $_SERVER['REQUEST_URI'] )['path'],'/' );
if ( file_exists( $root.$path ) )
{
if ( is_dir( $root.$path ) && substr( $path,strlen( $path ) - 1, 1 ) !== '/' )
{
header( 'Location: '.rtrim( $path,'/' ).'/' );
exit;
}
if ( strpos( $path,'.php' ) === false )
{
return false;
} else {
chdir( dirname( $root.$path ) );
require_once $root.$path;
}
} else {
include_once 'index.php';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment