Yar
Yar

Reputation: 4561

.htaccess mod_rewrite "Request exceeded the limit of 10 internal redirects due to probable configuration error. "

This is my .htaccess:

RewriteEngine ON

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php

Options -Indexes

It is used in a simple framework and the idea is to redirect request like: www.domain.com/subpage to index.php, which will call the subpage.

And my index.php is:

    function __autoload( $className ) {
    $className = strtolower( $className );
    // Trying to find proper directory. For pages - all the predefined languages' directories must be present and checked!
    $file =  'pages_pl/' . $className . '.php';
    if( file_exists( $file ) ) { require( $file ); }
    else {
        $file =  'pages_en/' . $className . '.php';
        if( file_exists( $file ) ) { require( $file ); }
        else {
            $file = 'lib/' . $className . '.php';
            if( file_exists( $file ) ) { require( $file ); }
            else {
                $file = 'admin/' . $className . '.php';
                if( file_exists( $file ) ) { require( $file ); }
            }
        }
    }
}


// Get page class
$pageClass = Parameters::page();

$language = null;

if( $pageClass == '' )   //if the class was not given, one depending on language will be called
{
//take language from the cookie, if present and valid
    if(isset($_COOKIE['lang']) && Language::exists($_COOKIE['lang'])) {
        $page = new Language::$MAINPAGE[$_COOKIE['lang']];
    }
    else {
        $defaultMainPage = Language::getDefaultMainPage();
        $page = new $defaultMainPage();  //default main page
    }
}     //if the specific class exists, it will be loaded
else if( class_exists( $pageClass ) ) //this makes __autoload() run
{
    $class = new ReflectionClass( $pageClass );
    if( $class->isInstantiable() )
        $page = new $pageClass();  //instantiate proper page here
    else
        $page = new Error404();
}
else
    $page = new Error404();

$language = $page->getLanguage(); //get the page's language     

?>
     //replaced triangle parentheses with round ones
    (head)
   ....
    (/head)
    (body)
        displayPart( 'top' );
        //print_r( $_SESSION );
            $page->displayContent();
            $page->displayPart( 'footer' );
        ?>
    (/body)
(/html)

And the Parameters class:

// This class decomposes URL address and returns: page, parameter1, parameter2 ...

class Parameters
{
    static private $isInitialized = false;
    static private $values;

    private function __construct() { 
    }

    static private function init()
    {
        if( self::$isInitialized == true ) return;

        $url = substr( $_SERVER['REQUEST_URI'], strrpos( $_SERVER['REQUEST_URI'], '/' ) + 1 );


      if( strpos( $url, '?' ) )
      {
          $url = substr($url, 0, strrpos($url, '?'));
      }

        self::$values = explode( ',', $url );

        self::$isInitialized = true;
    }

    static public function page()
    {
        self::init();
        return self::$values[0];
    }

    static public function get( $index )
    {
        self::init();
        if( $index < count( self::$values ) ) return self::$values[$index];
            else return null;       
    }
}

Can anyone help please?

Upvotes: 0

Views: 9960

Answers (2)

Yar
Yar

Reputation: 4561

OK. Seems like I have .htaccess that works:

RewriteEngine ON

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php/$1 [L]

Options -Indexes

Upvotes: 2

TerryE
TerryE

Reputation: 10888

Options        -Indexes -MultiViews

RewriteEngine On
RewriteBase   /

RewriteCond   %{REQUEST_FILENAME} !-f
RewriteCond   %{REQUEST_FILENAME} !-d
RewriteRule   ^                   index.php  [L,NS]

Your previous rule might be triggering a multiview / Directory Index subquery. It's safer to eliminate these possibilities if you don't use them.

Upvotes: 1

Related Questions