Page 1 of 1

rewrite file messing up links

Posted: Fri Jun 18, 2010 7:58 am
by aravona
I've got a website which I've copied over to work on on a local system. And I've noticed that the links are messed up, on both the real site and on the local one.

I've narrowed it down to a rewrite.php file... which is called in the index.php.

However I have no clue as to what the rewrite file is getting at. Whenever I use one of the links, it gives a 404 saying the page doesnt exist. What the page is doing, I think, it rewriting links from index.php?cmd=1 to... 'this-page' so that the link is named from the mysql database and not an ugly link.

However, its beyond my level of expertise to see why its just going to a dud page instead of going to the page set in the cmd case :S

This whole website is starting to drive me mad.

Code: Select all

<?php
    if(isset($_REQUEST['URL_Text'])){
     		
    	$_REQUEST['cmd']=18;
    	
        $SUBCat_NaMe=explode("-",$_REQUEST['URL_Text']);
        $lastValue=$SUBCat_NaMe[sizeof($SUBCat_NaMe)-1];
        
        for($i=0;$i<sizeof($SUBCat_NaMe);$i++){
    		if($WHEre==""){
    			$WHEre.=" name LIKE '".$SUBCat_NaMe[$i]."%'";
    		}else if($i==sizeof($SUBCat_NaMe)-1){
    			$WHEre.=" AND name LIKE '%".$SUBCat_NaMe[$i]."'";
    			//$WHEre.=" AND subcategory LIKE '%".$SUBCat_NaMe[$i]."'";
    		}else{
    			$WHEre.=" AND name LIKE '%".$SUBCat_NaMe[$i]."%'";
    		}
        }
        if($_REQUEST['URL_Text']=='new-items'){
         
            $_REQUEST['cmd']=5;
            
        }else{
            $query = "SELECT pID FROM ver_parent WHERE $WHEre";
            $result_SET = $class->ResultSet($query);
            $row_SET = $class->FetchObject($result_SET);
            $_REQUEST['CID']=$row_SET->pID;
        }
        
    }////end of if.
    
    if(isset($_REQUEST['URL_Text1'])){
 		$WHEre='';
    	$SUBCat_NaMe=explode("-",$_REQUEST['URL_Text1']);
        $lastValue=$SUBCat_NaMe[sizeof($SUBCat_NaMe)-1];
        
        for($i=0;$i<sizeof($SUBCat_NaMe);$i++){
    		if($WHEre==""){
    			$WHEre=" name LIKE '".$SUBCat_NaMe[$i]."%'";
    		}else if($i==sizeof($SUBCat_NaMe)-1){
    			$WHEre.=" AND name LIKE '%".$SUBCat_NaMe[$i]."'";
    			//$WHEre.=" AND subcategory LIKE '%".$SUBCat_NaMe[$i]."'";
    		}else{
    			$WHEre.=" AND name LIKE '%".$SUBCat_NaMe[$i]."%'";
    		}
        }
        $query = "SELECT cID FROM ver_child WHERE $WHEre";
        $result_SET = $class->ResultSet($query);
        if($class->NumRows($result_SET)!=0){
        
            $_REQUEST['cmd']=2;
            $row_SET = $class->FetchObject($result_SET);
            $_REQUEST['SCID']=$row_SET->cID;
            
        }else{

            $query = "SELECT prID FROM ver_pro WHERE $WHEre";
            $result_SET = $class->ResultSet($query);
            $_REQUEST['cmd']=7;
            $row_SET = $class->FetchObject($result_SET);
            $_REQUEST['pr']=$row_SET->prID;
            
        }
        
    }////end of ......
    
    
    if(isset($_REQUEST['URL_Text2'])){
 		$WHEre='';
    	$SUBCat_NaMe=explode("-",$_REQUEST['URL_Text2']);
        $lastValue=$SUBCat_NaMe[sizeof($SUBCat_NaMe)-1];
        
        for($i=0;$i<sizeof($SUBCat_NaMe);$i++){
    		if($WHEre==""){
    			$WHEre=" name LIKE '".$SUBCat_NaMe[$i]."%'";
    		}else if($i==sizeof($SUBCat_NaMe)-1){
    			$WHEre.=" AND name LIKE '%".$SUBCat_NaMe[$i]."'";
    			//$WHEre.=" AND subcategory LIKE '%".$SUBCat_NaMe[$i]."'";
    		}else{
    			$WHEre.=" AND name LIKE '%".$SUBCat_NaMe[$i]."%'";
    		}
        }
    
        $query = "SELECT prID FROM ver_pro WHERE $WHEre";
        $result_SET = $class->ResultSet($query);
        $_REQUEST['cmd']=9;
        $row_SET = $class->FetchObject($result_SET);
        $_REQUEST['pr']=$row_SET->prID;
        
    }////end of ......

?>
Thats the code in the rewrite.php .... if someone could please show me where/why its not going to the pages correctly, I'd be very grateful. In the meantime I will be trying to figure it out myself.

Kind regards,

Aravona.

Re: rewrite file messing up links

Posted: Fri Jun 18, 2010 2:22 pm
by Jade
Are you doing another redirect after you change the $_REQUEST variable? It sounds like one of your request variables is getting messed up in the process of the rewrite. Try printing them out before and after... also have you considered checking for trailing spaces in the re-written URL?

Code: Select all

print_r($_REQUEST);

//do your rewrite here

print_r($_REQUEST);

Re: rewrite file messing up links

Posted: Mon Jun 21, 2010 3:01 am
by aravona
I actually didn't write the code, this is one of the wonderful situations where I get dumped with a half working website.

I'll give the printing a go and see what happens :)

EDIT: Ok the re-write is still doing the same as before, which is linking to pages which do not exist giving me a 404 error on the site.

Even when I hard code the links to go straight where I want them to... the links are totally messed up.

The messed up site.

EDIT2:

This is the code from the index.php could this be the part messing it up...?

Code: Select all

if($_REQUEST['cmd']==18 || $_REQUEST['cmd']==2 || $_REQUEST['cmd']==3 || $_REQUEST['cmd']==4) {
        //http://projects.innova8ive.com/babygifts/index.php?cmd=18&CID=1
        //http://projects.innova8ive.com/babygifts/index.php?cmd=2&CID=62
        //http://projects.innova8ive.com/babygifts/index.php?cmd=3&CID=65
        //http://projects.innova8ive.com/babygifts/index.php?cmd=4&CID=7
        
        $query_get="SELECT pID,name FROM ver_parent WHERE pID=$_REQUEST[CID]";
        $result_get=$class->ResultSet($query_get);
        $row_get=$class->FetchObject($result_get);
        $bg_url=$Purl.$class->ReplaceSpaces($row_get->name).'/';
        
        if(@$_REQUEST['SCID']!=''){
            $query_get1="SELECT cID,name FROM ver_child WHERE cID=$_REQUEST[SCID]";
            $result_get1=$class->ResultSet($query_get1);
            $row_get1=$class->FetchObject($result_get1);
            $bg_url=$bg_url.$class->ReplaceSpaces($row_get1->name).'/';
        }

Re: rewrite file messing up links

Posted: Tue Jun 22, 2010 11:36 am
by Jade
Question, what link are you passing it and what is the messed up link you're ending up with?