The script works by taking the path requested by browser and splitting it to parts. The first part is treated as the article slug. If the slug is empty then it assumes the requested page is the home page and searches for it in the DB.
If the first part of the URL path is ‘css’ then the document is served as CSS. A bit stupid because it means any document can be served as CSS, but the goal was never to win design awards.
Inspired by this thread: http://www.kenyatalk.com/index.php?threads/php-help.31923/
Here is the script in action: http://one.xandar.xyz/ . Don’t hack me.
[PHP]// The directory our script is in. NOT the path
// Change backslashes to forward slashes. In case we are on MS Windows.
// Path info would work too but then we’d have to later compare with DOCUMENT_ROOT
// to check if it is the same path.
$scriptDir = str_replace(‘\’, ‘/’, DIR );;
// Check whether we are on https or http
$s = isset( $_SERVER[‘HTTPS’] ) && ( $_SERVER[‘HTTPS’] == ‘on’ ) ? ‘s’ : ‘’;
$serverProtocol = strtolower( $_SERVER[‘SERVER_PROTOCOL’] );
$protocol = substr($serverProtocol, 0, strpos($serverProtocol, ‘/’)) . $s;
// Check whether on port other than port 80
$port = (isset($_SERVER[‘SERVER_PORT’]) && $_SERVER[‘SERVER_PORT’] == ‘80’)
? ‘’ : (‘:’ . $_SERVER[‘SERVER_PORT’]);
// Final URL
$baseURL = $protocol . ‘://’ . $_SERVER[‘SERVER_NAME’] . $port;
// Document root of the server. This is different from script directory if
// the script is inside a folder in the document root.
$documentRoot = str_replace(‘\’, ‘/’, $_SERVER[‘DOCUMENT_ROOT’] );
// Remove the document root from script root so we are only left with
// the name of the directory, not the path.
$installDirectory = str_replace($documentRoot, ‘’, $scriptDir );
// Home URL without trailing /
$homeURL = $installDirectoryURL = $baseURL . $installDirectory;
// Get the current URL. Just in case we need it later
$currentURL = $baseURL . $_SERVER[‘REQUEST_URI’];
$currentPath = str_replace( $homeURL, ‘’, $currentURL );
// Remove the script name from path if the first part is
// the name of the script.
$scriptInfo = pathinfo(FILE);
$fileNameWithSlash = ‘/’ . $scriptInfo[‘basename’];
if ( !$config[‘using_mod_rewrite’] ) {
$homeURL .= $fileNameWithSlash;
}
if ( 0 === strpos($currentPath, $fileNameWithSlash ) ) {
$currentPath = substr($currentPath, strlen($fileNameWithSlash) );
}
// Remove get vars if present
if ( FALSE !== strpos($currentPath, ‘?’) ) {
$currentPath = strstr($currentPath, ‘?’, true);
}
// URL arguments
$urlArgs = explode( ‘/’, trim($currentPath, ‘/’) );[/PHP]
cc @Pos€i.Don