Skip to content

Instantly share code, notes, and snippets.

@mralexgray
Forked from lolautruche/gist:1447481
Created January 10, 2012 17:25
Show Gist options
  • Save mralexgray/1590118 to your computer and use it in GitHub Desktop.
Save mralexgray/1590118 to your computer and use it in GitHub Desktop.
eZ Publish router script to be used with PHP 5.4 built-in webserver
<?php
// Router script for running eZ Publish CMS on top of PHP 5.4 built-in webserver
// WARNING !!! Use it for development purpose ONLY !!!
// This script is provided as is, use it at your own risk
// Determine which script to redirect to depending on rewrite rule to apply
// If the request needs to be served directly, $script needs to be null
$uri = $_SERVER['REQUEST_URI'];
$script = 'index.php';
if ( strpos( $uri, '/api/' ) === 0 )
{
$script = 'index_rest.php';
}
else if ( preg_match( '#^/([^/]+/)?content/treemenu.*#', $uri ) )
{
$script = 'index_treemenu.php';
}
else if (
strpos( $uri, '/share/icons/' ) === 0 ||
strpos( $uri, '/var/storage/packages/' ) === 0 ||
strpos( $uri, '/favicon.ico' ) === 0 ||
strpos( $uri, '/design/standard/images/favicon.ico' ) === 0 ||
strpos( $uri, '/robots.txt' ) === 0 ||
strpos( $uri, '/w3c/p3p.xml' ) === 0 ||
preg_match( '#^/extension/[^/]+/design/[^/]+/(stylesheets|flash|images|lib|javascripts?)/.*#', $uri ) ||
preg_match( '#^/design/[^/]+/(stylesheets|images|javascript)/.*#', $uri ) ||
preg_match( '#^/var/([^/]+/)?storage/images(-versioned)?/.*#', $uri ) ||
preg_match( '#^/var/([^/]+/)?cache/(texttoimage|public)/.*#', $uri ) ||
preg_match( '#^/packages/styles/.+/(stylesheets|images|javascript)/[^/]+/.*#', $uri ) ||
preg_match( '#^/packages/styles/.+/thumbnail/.*#', $uri )
)
{
$script = null;
}
if ( $script && file_exists( $script ) )
{
// First setup some missing $_SERVER vars
if ( strpos( $_SERVER['HTTP_HOST'], ':' ) )
{
list( $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'] ) = explode( ':', $_SERVER['HTTP_HOST'], 2 );
}
else
{
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$_SERVER['SERVER_PORT'] = '80';
}
$_SERVER['SERVER_ADDR'] = $_SERVER['REMOTE_ADDR'];
if ( !isset( $_SERVER['QUERY_STRING'] ) )
$_SERVER['QUERY_STRING'] = '';
if ( !isset( $_SERVER['SCRIPT_FILENAME'] ) )
$_SERVER['SCRIPT_FILENAME'] = realpath( $script );
require_once( $script );
}
else
{
return false;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment