Click here to Skip to main content
15,169,285 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello .
I have a project written in PHP based on MVC.
The problem is I get a 301 error on apache but not on windows servers.
I converted web.config to htaccess file using an online tool.
now the details of the problem :
the url is like : www.abc.com?cid=0 in which cid is id of a root of a explorer tree structure. now each time this url is called this cid should change to return the childs of that node.
The code in the constructure of the controller and where the loop happens :

C#
function __construct() {

    parent::__construct ();
    Auth::handleLogin ();

    if (! (isset ( $_GET ['cid'] ) && strlen ( $_GET ['cid'] ) > 0)) {
        header ( 'location: ' . URL . "newscategories?cid=0" );
    }
 
}


The actual method in controller to handle request :

PHP
function index() {
        if (Auth::handleLogin () && Auth::HasPermission ( PER_MNG_NEWS_GROUP )) {
            // -------------
            $cid = 0;
            if (isset ( $_GET ['cid'] ) && strlen ( $_GET ['cid'] ) > 0) {
                $cid = $_GET ['cid'];
            }
            $this->view->editid = '';
            if (isset ( $_GET ['e'] )) {
                $this->view->editid = $_GET ['e'];
            }
            // ---------------
            $tknid = self::get_token_id ();
            $tknvl = self::get_token ();
            $_SESSION ['TOKENEXPIRETIME'] = time () + TokenDeadLine;

            $this->view->cat_list = $this->model->getcats ( $cid );
            $this->view->cat_path = $this->model->getcatpath ( $cid );

            if (sizeof ( $this->view->cat_path ) == 0)
                header ( 'location: ' . URL . "newscategories?cid=0" );
            $this->view->cid = $cid;
            $this->view->tokenid = $tknid;
            $this->view->tokenvalue = $tknvl;
            $this->view->render ( 'news/categories' );
        }



I should mention this works fine on IIS and the content of htaccess is :

XML
#SECURITY

<IfModule mod_rewrite.c>
RewriteEngine On

#REWRITE RULES
#RULE IMPORTED RULE 1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [L]
</IfModule>


would be very grateful if someone could hep me please.
Posted

1 solution

This may be sourced by role looping when using the RewriteRule [L] flag in .htaccess files. See RewriteRule Flags[^] for a description.

You may also inspect the full 301 response to check the passed Location. It may indicate which part is not rewritten as expected.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900