[thelist] Directory style query strings without using mod_rewrite

Garrett Coakley garrett at polytechnic.co.uk
Wed Jul 18 12:21:13 CDT 2001


On Wed, 18 Jul 2001 16:43:44 +0100
"Richard Livsey" <R.Livsey at cache-22.co.uk> wrote:

> Basically as the subject says, I want to mask query strings as directory
> style URL's but cant use mod_rewrite.
> 
> Does anyone know how this would be done?
> Server is PHP/Apache.


I'm in the process of writing an article for evolt which outlines how to do this. The article is still a week or two away (gotta clean up the code... v. messy *:), but this is the quick 'n' dirty version.

You can see this in action at http://www.oxfordnaturalproducts.com.

First thing you need to do is set up a php file which will process the query string. I've called mine "site".

Then you need to set up apache so it processes "site" as a PHP file. In your .htaccess file you need this line:

<Files site>
	ForceType application/x-httpd-php
</Files>

So, onto "site" itself...

It has a call to a function called processURI(). What processURI does is split the request string (everything after the domain) on the /'s and then builds an array to pass back to the various functions throughout the site like the navigation elements etc.

Something like this:

function processURI() {
	//explode the URI using '/' as a delimeter
	$array = explode("/",$REQUEST_URI);
	//which company division are we in?
	//we start at pos [2] cos [1] is site
	$loc = $array[2];
	//better check if we're at the root level of that company or at a page
	$page = $array[3];
	// build the array
	$url_array = array(
			"location" => $loc, 
			"page" => $page
			);
	// return our array
	return $url_array ;
}



This is a really rough version... you'd probably want to put some sanity checking in there to make sure nasty people don't break your creation.
 
Once you've got an array with all your variables, then you can do what ever you want. Use them for DB queries, pull in content from static files... all sorts of funky stuff.

There's an article on phpbuilder.com which outlines a method similar to this, I'm not online right now, but if you have a look in the Articles section, you should see it.

HTH... if not, just holler.

G.

-- 
----------------------------------------------------------------------------
WORK: http://spiked.co.uk/
PLAY: http://polytechnic.co.uk/




More information about the thelist mailing list