Clean(er) CubeCart 4 URLs

This modification may not function properly if you have selected “Use FTP generated PHP pages (If all other methods fail)” as the URL Build Option in your CubeCart settings.

If you are using CubeCart version 4 there is a fairly good chance you are making use of the search engine friendly URL features. This will replace a “dirty”, query laced URL with a much cleaner search engine and user friendly URL modeled off of traditional static page URLs.

In making the URL clean, a .html extenstion is added to the end of the URL. For users like me, it’s not quite clean enough.

By leaning on WordPress in many of my web development projects, I’ve grown accustom to having my URLs end with no file extension, just a slash (eg. mycubecart.com/some/friendly/url/). This is what we aim to accomplish here.

This modification requires the alteration of the following CubeCart 4 files:

  1. cubecart root/index.php
  2. cubecart root/includes/sef_urls.inc.php

Part 1 – CubeCart Version 4.3.0 Only

1. Open index.php in a text, html or php editor.

2. Find:

53
	if(preg_match('#([a-z]{1,6})_([a-z0-9+]+).?([a-z]+)?(?.*)?$#i', $_SERVER['REQUEST_URI'], $matches)) {

3. Replace with:

53
54
55
56
57
58
// BEGIN: MyCubeCart.com Mod - cleaner urls
	if(preg_match('#([a-z]{1,6})_([a-z0-9+]+).?([a-z]+)?(/)?(?.*)?(/)?$#i', $_SERVER['REQUEST_URI'], $matches)) {
/* Replaced
	if(preg_match('#([a-z]{1,6})_([a-z0-9+]+).?([a-z]+)?(?.*)?$#i', $_SERVER['REQUEST_URI'], $matches)) {
*/
// END: MyCubeCart.com Mod - cleaner urls

4. Save file and upload.

Part 1 – CubeCart Version 4.2.x

1. Open index.php in a text, html or php editor.

2. Find:

53
	preg_match('#([a-z]{1,6})_([a-z0-9+]+).?([a-z]+)?(?.*)?$#i', $_SERVER['REQUEST_URI'], $matches);

3. Replace with:

53
54
55
56
57
58
// BEGIN: MyCubeCart.com Mod - cleaner urls
	preg_match('#([a-z]{1,6})_([a-z0-9+]+).?([a-z]+)?(?.*)?(/)?$#i', $_SERVER['REQUEST_URI'], $matches);
/* Replaced
	preg_match('#([a-z]{1,6})_([a-z0-9+]+).?([a-z]+)?(?.*)?$#i', $_SERVER['REQUEST_URI'], $matches);
*/
// END: MyCubeCart.com Mod - cleaner urls

4. Save file and upload.

Part 2 – All Version CubeCart 4.2.x – 4.3.0

Line numbers below are based on that of 4.3.0. The replacements demonstated are consistent but the line numbers will vary based on the actual version of CubeCart 4 you are using.

1. Open sef_urls.inc.php.

2. Find (5 occurrences – lines: 86, 121, 147, 158 and 168):

86
	$ext	= ($config['sefserverconfig'] == 3) ? '.php' : '.html';

3. Replace each occurrence with:

86
87
88
89
90
91
// BEGIN: MyCubeCart.com Mod - cleaner urls
	$ext = '/';
/* Replaced
	$ext	= ($config['sefserverconfig'] == 3) ? '.php' : '.html';
*/
// END: MyCubeCart.com Mod - cleaner urls

4. Save file and upload.

Modification Complete!

Now your CubeCart URL’s will be so clean, the glare may hurt your visitors eyes!

Tags: , , , ,

Leave a Reply

You must be logged in to post a comment.