Page 1 of 1

mod_rewrite causing problems with server vars

Posted: Thu Dec 21, 2006 9:34 am
by mattcooper
Hello all,

I'm using the following code in .htaccess to acheive silent redirection for friendly URLs:

Code: Select all

AddType application/x-httpd-php5 .php .phtml
RewriteEngine on
RewriteRule /infopods/([^/]+)/([^/]+)/([^/]+)$ /infopods.php?param=$1&id=$2&title=$3 [L]
RewriteRule /infopods/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ /infopods.php?param=$1&pre_id=$2&id=$3&title=$4 [L]
RewriteRule /whatson/results/([^/]+)/([^/]+)$ /whatson.php?results&ev_id=$1&title=$2 [L]
RewriteRule /findit/results/([^/]+)$ /findit.php?results&svc_id=$1 [L]
RewriteOptions MaxRedirects=3
Also on the site in question is a flash detection script, from Adobe's website, that uses an external script called 'AC_RunActiveContent.js'.

I'm constructing a breadcrumbing function:

Code: Select all

function construct_Breadcrumb() {
		
			$item_type = $_REQUEST[param];
			# what did we get?
			switch($item_type) {
			
				case "pod": # it's top-level, so all we have to do is show that we're on the infopods homepage
				$breadcrumb_RetVal = "Infopods";
				break;
				
				case "article": # the user has chosen an infopod to browse, so we need to show them which one
				$breadcrumb_RetVal = "Infopods > ".$_REQUEST[title];
				$_SESSION[pod] = $_REQUEST[title];
				break;
				
				case "subarticle": # they've now chosen an articel from within the pod being viewed
				$breadcrumb_RetVal = "Infopods > ".$_SESSION[pod]." > ".$_REQUEST[title];
				$_SESSION[subarticle] = $_REQUEST[title];
				break;
				
				case "item": # final level - we need to show the pod, article and subarticle titles
				$breadcrumb_RetVal = "Infopods > ".$_SESSION[pod]." > ".$_SESSION[article]." > ".$_REQUEST[title];
			
			} # endswitch
			return "Home > ".$breadcrumb_RetVal;	
		
		}
This is supposed to grab the $_GET/$_REQUEST method to echo a title to the browser, as well as store it in a session for echoing out when we're on the next level of the crumbing.

So, what we should see is something like:

Home > Infopods > Article > Subarticle > Item

However, when the mod_rewrite stuff was placed in .htaccess, the server vars appear to be interfered with, and I now get:

Home > Infopods > AC_RunActiveContent.js > Subarticle ...

Can anyone suggest why this may be, and how it might be fixed? Is there something wrong with the mod_rewrite scripting??

thanks in advance :)

Posted: Thu Dec 21, 2006 11:16 am
by Kieran Huggins
If you're parsing the values from the URL you may want to use $_SERVER['REQUEST_URI'] as it contains the un-modified URL string that called the page. It doesn't change during a mod_rewrite.

Cheers,
Kieran