hey, i am trying to rewrite a url from this one:

http://www.example.com/links.php?view=category&id=43

to this one:

http://www.example.com/links/category/43

the rewrite works, but the user has to enter to www.example.com/links first and then he chooses a category.
the problem is that when a category isnt selected when he is at- www.example.com/links then the server returns a 404 error.

can someone tell me how can i fix it?

    you're not posting your stab at a regular expression so it's tough to assist. At the risk of spoiling your post, you might consider just having this line in your root .htaccess file:

    ErrorDocument 404 /404.php
    

    then, if you discern a valid request simply require() that page and set the variables like $view=category &$id=13 etc. Also be sure you return a 200 OK header (you might consider 299 if you have a certain bug I think with Apache)

    here is some code I use for my 404 page, which will give you some ideas:

    
    
    
    
    //2009-04-24, new method: presumed 404 page masquerading as other page, get page from REQUEST_URI
    $a=explode('?',$GLOBALS['REQUEST_URI']);
    $a=preg_split('/\\\|\//',$a[0]);
    $thispage=$a[count($a)-1];
    if(count($a)>2){
    	$thisfolder=$a[count($a)-2];
    }else{
    	$thisfolder='';
    }
    //trust me there are more modern ways to do this see parse_str() if you have php 5
    if($a[1]){
    	//globalize query string
    	$a=explode('&',trim($a[1],'&'));
    	foreach($a as $pair){
    		if(!stristr($pair,'='))continue;
    		//safest most reliable way
    		if(stristr($pair,'_SESSION') || stristr($pair,'HTTP_SESSION_VARS') || stristr($pair,'_SERVER') || stristr($pair,'HTTP_SERVER_VARS') || stristr($pair,'PHP_AUTH_USER') || stristr($pair,'PHP_AUTH_PW') || stristr($pair,'_ENV') || stristr($pair,'HTTP_ENV_VARS'))continue;
    
    	$var=substr($pair,0,strpos($pair,'='));
    	$var=str_replace('[','[\'', str_replace(']','\']',$var));
    	$value=substr($pair,strpos($pair,'=')+1);
    	$value=(is_numeric($value)?'':'\'') . str_replace("'","\'",urldecode($value)) . (is_numeric($value)?'':'\'');
    	@eval('global $'.preg_replace('/\[.+/','',$var).';');
    	@eval('$'.$var.'='.$value.';');
    }
    }
    
    
    if(preg_match('/^\/[-a-z0-9]+$/i',$GLOBALS['REDIRECT_URL'])){
    	$str=ltrim(str_replace('-',' ',$GLOBALS['REDIRECT_URL']),'/');
    	if($a=q("SELECT * FROM cms1_articles WHERE REPLACE(KeywordsTitle,'-',' ')='".addslashes($str)."'", O_ROW)){
    		$Articles_ID=$a['ID'];
    		$Category=$a['Category'];
    		$blogType=$a['SubCategory'];
    		$thispage='news-*************s.php';
    		header("HTTP/1.1 299 OK");
    		require('news-*************s.php');
    		exit;
    	}
    }
    
    
      Write a Reply...