Forums / Cotonti / Support / I need help with mod_rewrite

mod_rewrite for dummies

Trustmaster
#28007 2011-01-19 05:25
It is a second step. Now you can edit your URLs (Admin => Other => URLs) so that you add such rules to your datas/urltrans.dat:
list	c=*	/{$c}/
page	*	{page_url_structure()}
*	*	{$_area}.php
Page URLs would need a function, since they don't have category names in their parameters. Create a file system/functions.custom.php and add a function to make page urls:
function page_url_structure(&$args)
{
	global $sed_cat, $pag, $row, $rpagecat, $c, $newpagecat;


	$page_cat = (!empty($sed_cat[$rpagecat]['path']) && empty($page_cat)) ? $sed_cat[$rpagecat]['path'] : $page_cat;
	$page_cat = (!empty($sed_cat[$pag['page_cat']]['path']) && empty($page_cat)) ? $sed_cat[$pag['page_cat']]['path'] : $page_cat;
	$page_cat = (!empty($sed_cat[$row['page_cat']]['path']) && empty($page_cat)) ? $sed_cat[$row['page_cat']]['path'] : $page_cat;
	//$page_cat = (!empty($sed_cat[$args['c']]['path']) && empty($page_cat)) ? $sed_cat[$args['c']]['path'] : $page_cat;
	$page_cat = (!empty($sed_cat[$newpagecat]['path']) && empty($page_cat)) ? $sed_cat[$newpagecat]['path'] : $page_cat;

	if (empty($page_cat)) $page_cat = 'articles';
	if($args['id'])
	{
		$url = $page_cat.'/';
		$url .= $args['id'] . '/';
		unset($args['id']);
	}
	elseif($args['al'])
	{
		$url = $page_cat.'/';
		$url .= urlencode($args['al']) . '/';
		unset($args['al']);
	}
	return $url;
}

And finally add mod_rewrite rules to your .htaccess:
# Rewrite engine options
Options FollowSymLinks -Indexes
RewriteEngine On
# Path to Cotonti
RewriteBase /

# Protect static paths
RewriteRule (datas|images|js|skins|plugins|system)/(.*)$ $1/$2 [L]

# Pages by ID
RewriteRule ([a-z]+)/([0-9]+)/ page.php?id=$2 [QSA,NC,NE,L]
# Pages by alias
RewriteRule ([a-z]+)/([a-zA-Z0-9\-_]+)/ page.php?al=$2 [QSA,NC,NE,L]
# Category
RewriteRule ([a-z]+)/ list.php?c=$1 [QSA,NC,NE,L]
May the Source be with you!