1

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.
aKn1ghtOut
  • 53
  • 8
  • I'm not sure how your .htaccess relates to your issue. Strip everything from index.php and make sure all the URLs actually get handled by index.php. Otherwise if the issue was in the PHP script you should have seen an error message rather than a 500 error. – Tony Bogdanov Sep 24 '16 at 15:25
  • Thats what happens, other than resource files which are in qn_themes. There is no 404 in the root. The 404 file is in the qn_frontend folder. So, thats handled here too. I don't know what's causing this, so I posted maximum info here. I also tried online and am now checking the apache logs. – aKn1ghtOut Sep 24 '16 at 15:27
  • If you see a 500 error, then turn display errors on or check your error log to find out what the actual error message is. How to display errors / turning error reporting on: http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – M. Eriksson Sep 24 '16 at 15:27
  • Added the error from the error log though I have no idea what that means. The whole index.php is here and I can't seem to be able to pinpoint the problem. @magnus-eriksson – aKn1ghtOut Sep 24 '16 at 15:34
  • Do you get this on all URL's or just some? – M. Eriksson Sep 24 '16 at 15:42
  • The local host for this on my machine is cf2. If I go to cf2/Play, it works but if I go to cf2/Play/, it does not. – aKn1ghtOut Sep 24 '16 at 15:44
  • 1
    Solved it: It was a htaccess issue after all. Just googled the error from the error log and the first one had the answer. The link is [link](http://stackoverflow.com/questions/33477428/apache-web-server-ah00125-request-exceeded-the-limit-of-10-subrequest-with-fal) – aKn1ghtOut Sep 24 '16 at 15:51

0 Answers0