Mod_Rewrite Help

Soldato
Joined
10 Dec 2003
Posts
6,348
I'm using a heavily modified installation of CubeCart v3.0.17 with an SEO Mod, which changes this:

Code:
http://localhost/brandnew/index.php?act=viewCat&catId=1

To this:

Code:
http://localhost/brandnew/test-category/cat_1.html

Which is all very nice, but I'd prefer it without the 'cat_1.html' ending. I've done a lot of searching on Google but found nothing useful, except one article that said, to make such a change, there would be a problem with duplicate products.

So understanding that potential problem, I've settled on the idea that 'test-category/01/' would be a better alternative. But I've yet to find anything that will help me acheive such a result in .htacess.

So I need to rewrite 'cat_1.html' to just '/01/'.

Can anybody help? It would much be much appreciated. :)
 
Oh, and this is the code I have in the .htaccess at the moment.

Code:
RewriteEngine On
RewriteCond %{QUERY_STRING} (.+) 
RewriteRule cat_(.*).html index.php?act=viewCat&catId=$1&%1 [L]
RewriteRule cat_(.*).html index.php?act=viewCat&catId=$1 [L]
RewriteCond %{QUERY_STRING} (.+) 
RewriteRule prod_(.*).html index.php?act=viewProd&productId=$1&%1 [L]
RewriteRule prod_(.*).html index.php?act=viewProd&productId=$1 [L]
RewriteCond %{QUERY_STRING} (.+) 
RewriteRule info_(.*).html index.php?act=viewDoc&docId=$1&%1 [L]
RewriteRule info_(.*).html index.php?act=viewDoc&docId=$1 [L]
RewriteCond %{QUERY_STRING} (.+) 
RewriteRule tell_(.*).html index.php?act=taf&productId=$1&%1 [L]
RewriteRule tell_(.*).html index.php?act=taf&productId=$1 [L]
 
This should do the trick:

Code:
RewriteRule /([0-9]+)/?$ /cat_$1.html

Edit: actually, you'll have to fiddle around with what's already there or it'll be ignored due to the [L] (last rule) directives on the current rules.
 
Last edited:
This should do the trick:

Code:
RewriteRule /([0-9]+)/?$ /cat_$1.html

Edit: actually, you'll have to fiddle around with what's already there or it'll be ignored due to the [L] (last rule) directives on the current rules.

What kind of fiddling around? I really have no idea about .htaccess, as I normally just copy & paste solutions from the web haha.
 
There is a file in the SEO mod that defines the URL structure. sef_urls.inc.php i think it is, in the /include folder. In that file will be a function along the lines of generateProductURL() - you can tweak that to get the desired effect.

(excuse the flaky details, i'm not at work where my coding is. If you are still struggling, drop me an email (in trust))

Matt
 
Thank you.

I've found that page, but any values I change results in an 'object not found' page on the newly generated URLs.

I can change the code, and the links are showing how I wish but then I get a 404. Any ideas why this is happening or how to get around it? Thanks. :)
 
Here is the function I've found:

Code:
function generateCategoryUrl($catid) {

	global $glob, $db, $config, $lang_folder;

	if($config['sefserverconfig'] == 0 || $config['sefserverconfig'] == 3)
		$sefpre = 'cat_';
	else
		$sefpre = 'c_';

	if($config['sefserverconfig'] == 3)
		$ext = '.php';
	else
		$ext = '.html';

	if(is_numeric($catid)) {

		if($config['sefcustomurl'] == 1) $sefcustomurls = "cat_sefurl,";
		$query = "SELECT $sefcustomurls cat_name, cat_id, cat_father_id FROM ".$glob['dbprefix']."CubeCart_category WHERE cat_id='".$catid."'";
		$sef_categories = $db->select($query);
		
		$prevDirSymbol = $config['dirSymbol'];
		$config['dirSymbol'] = '/';
		$prevLang = $lang_folder;
		$lang_folder = $config['defaultLang'];
		$cat = getCatDir($sef_categories[0]['cat_name'], $sef_categories[0]['cat_father_id'], $sef_categories[0]['cat_id'], FALSE, TRUE);
		$config['dirSymbol'] = $prevDirSymbol;
		$lang_folder = $prevLang;
		
		// using custom urls?
		if($config['sefcustomurl'] == 1) {
			if(strlen($sef_categories[0]['cat_sefurl']) > 0) {
				$cat = $sef_categories[0]['cat_sefurl'];
			}
		} 
		
		$cat = generateSafeUrls($cat);				
		$cat = strtolower($cat) . "/". $sefpre . $catid . $ext;
	} else {
		$cat = "";
		$cat = generateSafeUrls($cat);
		$cat = strtolower($cat) . $sefpre . $catid . $ext;
	}

	return $cat;
}
 
Ahhh, I've forgotten that I need to edit the .htaccess, too. Playing around with it at the moment, but it's not working too well. Better results, though.
 
Sorry, didn't get any email notifications of this thread. I forgot to mention about changing the .htaccess file too. FYI, the new version of CubeCart has the mod_rewrite stuff built in. From what i've seen of it though, it's going downhill. Magento looks like one to keep an eye on.

Glad you got it sorted.

Matt
 
Back
Top Bottom