Skip to content

Instantly share code, notes, and snippets.

@yurivictor
Created April 18, 2014 11:36
Show Gist options
  • Save yurivictor/11039349 to your computer and use it in GitHub Desktop.
Save yurivictor/11039349 to your computer and use it in GitHub Desktop.
Quick and dirty WordPress router
<?php
// php -S localhost:9393 router.php
$root = $_SERVER[ 'DOCUMENT_ROOT' ];
chdir( $root );
$path = '/' . ltrim( parse_url( $_SERVER['REQUEST_URI'] )['path'], '/' );
set_include_path( get_include_path() . ':' . __DIR__ );
if ( file_exists( $root . $path ) ) {
if ( is_dir( $root . $path ) && substr( $path, strlen( $path ) - 1, 1) !== '/' ) {
$path = rtrim( $path, '/' ) . '/index.php';
}
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