Page 1 of 1

How to pass parameters when using mod_rewrite

Posted: Fri Aug 08, 2008 2:03 am
by oi_antz
I am writing a category/catalog module for a system that uses mod_rewrite with $config['use_hierarchy'] = true, and wondering if CMSms has a parser that will take parameters from the url and translate to $_GET variables. I can make one myself, I've done it several times, just wondering if there is a standard way to do this for compliance.

Eg.
Traditional url might be:
domain.com/index.php?page=browse-products&productId=43

Pretty url might be:
domain.com/productId/43/browse-products.html

Is this functionality provided for already, or am I right to write my own uri interpreter?

Re: How to pass parameters when using mod_rewrite

Posted: Fri Aug 08, 2008 2:18 am
by Dr.CSS
Well news and others do it so you may want to look thru them to see how...

Re: How to pass parameters when using mod_rewrite

Posted: Fri Aug 08, 2008 2:29 am
by timstl
There are a couple ways that you *can* do it.

The best way is to use setparameters/registerroute. There are docs that pretty much explain it, and the Skeleton module has a good example. Here is an example of how I did it, though:

In whatever.module.php you have a SetParameters function.

Code: Select all

function SetParameters()
	{
	
		// create friendly URL paremter 'page'
		$this->CreateParameter('page', '', $this->lang('help_page'));
		$this->SetParameterType('page', CLEAN_STRING);
		$this->RegisterRoute('/page\/(?P<pg>[0-9]+)$/', array('action'=>'default'));
       }
Then, when you create link, you have to pass the friendly_url parameter in...

Code: Select all

$i = 1; // for example			
$pages .= $this->CreateFrontendLink(
			$id,
			$returnid,
			'default',
			$i,
			array('pg' => $i),
			'',
			'',
			'',
			$class,
			false,
			'page/'.$i.'/'
			);
So your link will show up as http://www.whatever.com/page/1/ . Because you've setup the parameter/route, CMS will know that 1 is the "pg" variable, and that it's supposed to call the "default" action.

Re: How to pass parameters when using mod_rewrite

Posted: Fri Aug 08, 2008 4:26 pm
by Pierre M.
mod_rewrite + parameters => may be QSA (query string append) in the Apache doc can help.
domain.com/shop/browse.html?id=43

Pierre M.