I am developing a framework, which I am also implementing on a website as I develop it. My .htaccess has
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^Themes/(.*)$ /qn_themes/$1 [R=301,NC,L]
FallbackResource index.php
and in the index.php, I manage the routing Below are the contents of index.php
<?php
include 'qn_config/conf.php'; //not important
function getPath($elem)
{
if(! empty($elem[0]))
{
$theElem = array_shift($elem);
return '/' . $theElem . getPath($elem);
}
else
{
return ".php";
}
}
$page = 0;
$path = ltrim($_SERVER['REQUEST_URI'], '/'); // Trim leading slash(es)
$elements = explode('/', $path); // Split path on slashes
if(empty($elements[0])) { // No path elements means home
$page = "Home";
}
else
{
$page = array_shift($elements);
}
$path = 'qn_frontend/' . $page . getPath($elements);
if (!file_exists($path)) {
header("Location: " . $GLOBALS['host'] . '404');
}
include 'qn_themes/'. $currTheme.'/base.php' ;
?>
This is working for urls such as domain.com/play but when I enter domain.com/play/account, it gives me a 500 error instead of redirecting to 404. I've looked up and down but to o avail. Can anybody help me out please.
[EDIT] I just noticed that I have put a lot of code for nothing. I stripped it down to
<?php
include 'qn_config/conf.php';
$path = ltrim($_SERVER['REQUEST_URI'], '/'); // Trim leading slash(es)
$elements = explode('/', $path); // Split path on slashes
if(empty($elements[0])) { // No path elements means home
$path = 'qn_frontend/Home.php';
}
else
$path = 'qn_frontend/' . ltrim($_SERVER['REQUEST_URI'], '/') . '.php';
if (!file_exists($path)) {
header("Location: " . $GLOBALS['host'] . '404');
}
include 'qn_themes/'. $currTheme.'/base.php' ;
?>
However, I still get the internal server error 500. I opened up the error_log. This line was repeated a lot of times
[core:error] [pid 4943] [client 127.0.0.1:60258] AH00125: Request exceeded the limit of 10 subrequest nesting levels due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.