Created
April 13, 2012 16:32
-
-
Save SemanticallyNull/2378155 to your computer and use it in GitHub Desktop.
Alternative index.php for Sapphire-CMS/SilverStripe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/************************************************************************************ | |
************************************************************************************ | |
** ** | |
** If you can read this text in your browser then you don't have PHP installed. ** | |
** Please install PHP 5.0 or higher, preferably PHP 5.2. ** | |
** ** | |
************************************************************************************ | |
************************************************************************************/ | |
/** | |
* This script bolts on top of SilverStripe/Sapphire to allow access without the use of .htaccess | |
* rewriting rules. | |
*/ | |
// This is the URL of the script that everything must be viewed with. | |
// Include a trailing slash, always. | |
define('BASE_SCRIPT_URL','/'); | |
$ruLen = strlen($_SERVER['REQUEST_URI']); | |
$snLen = strlen(BASE_SCRIPT_URL); | |
$isIIS = (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false); | |
$isNginx = (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false); | |
// IIS will populate server variables using one of these two ways | |
if($isIIS) { | |
if($_SERVER['REQUEST_URI'] == $_SERVER['SCRIPT_NAME']) { | |
$url = ""; | |
} else if($ruLen > $snLen && substr($_SERVER['REQUEST_URI'],0,$snLen) == ($_SERVER['SCRIPT_NAME'] . '/')) { | |
$url = substr($_SERVER['REQUEST_URI'],$snLen+1); | |
$url = strtok($url, '?'); | |
} else { | |
$url = $_SERVER['REQUEST_URI']; | |
if($url[0] == '/') $url = substr($url,1); | |
$url = strtok($url, '?'); | |
} | |
} elseif($isNginx) { | |
$url = substr($_SERVER['REQUEST_URI'],$snLen); | |
$url = strtok($url, '?'); | |
} else { | |
if($ruLen > $snLen && substr($_SERVER['REQUEST_URI'],0,$snLen) == ($_SERVER['SCRIPT_NAME'] . '/')) { | |
$url = substr($_SERVER['REQUEST_URI'],$snLen+1); | |
$url = strtok($url, '?'); | |
} else { | |
$url = ""; | |
} | |
} | |
$_GET['url'] = $_REQUEST['url'] = $url; | |
$fileName = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . $url; | |
require_once('sapphire/main.php'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment