So, when you use mod_rewrite does it redirect to the index.php file muliple times?
index.php
buildQuery();
module_Load(empty(REQUEST[1])?'default':module_Load(REQUEST[1]));
// +-------------------------------------------------------------------------------------------------------------------
function module_Load($module) {
$modules = [
'page' => "pages",
];
require_once 'sources/'.(array_key_exists($module, $modules) ? $modules[$module]:'default').'.php';
die;
}
function buildQuery() {
// Remove Double Forward Slashes...
$_SERVER['REQUEST_URI'] = str_replace('//', '/', $_SERVER['REQUEST_URI']);
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
if (strpos($path, '..')) die('Hacking Attempt Detected, Aborting');
$path = str_replace(['\\', '%5C'], '/', substr(
$path,
strlen(pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME))
));
if (empty($path))
define('REQUEST', [ 'index' ]);
else {
$path = explode('/', $path);
foreach ($path as &$p) $p = urldecode($p);
define("REQUEST", $path);
}
}
.htaccess
RewriteEngine On
RewriteRule !(^(images|downloads))|(\.(gif|jpg|png|css|js|html|txt|ico|zip|rar|pdf|xml|mp3|mp4|mpg|flv|swf|mkv|ogg|avi|woff|woff2|svg|eot|ttf|json|webmanifest)$) index.php
The problem is that if you visit localhost/page it will load the pages.php AND the default.php unless I add the die into the module_Load function? (the only reason I can see for this behaviour is if the mod_rewrite is doing something strange?