Force correct category and item names in static links
In the SiteBuilder system, a static link displays the category or item number and name. The number is used by the system to determine the category or item, but the name is not used. It is there for display only. So if someone manually changes the name in a static link, the item or category will still show. For instance, a link at:
http://yoursite/category_37/Jewelry.htm
and
http://yoursite/category_37/Jewels.htm
will both point to the same item.
If you want to change this so that someone manually entering an incorrect name sees an error page, you can use the following modification:
-
Open the .htaccess file in the public_html directory of your site
-
Change the lines:
RewriteRule category_(.*)/(.*)/(.*).htm$ catalog.php?category=$1&page=$2 RewriteRule category_(.*)/(.*).htm$ catalog.php?category=$1
to:
RewriteRule category_(.*)/(.*)/(.*).htm$ catalog.php?category=$1&page=$2&cname=$3 RewriteRule category_(.*)/(.*).htm$ catalog.php?category=$1&cname=$2
-
Change the lines:
RewriteRule item_(.*)/(.*)/(.*).htm$ catalog.php?item=$1&catid=$2 RewriteRule item_(.*)/(.*).htm$ catalog.php?item=$1
to:
RewriteRule item_(.*)/(.*)/(.*).htm$ catalog.php?item=$1&catid=$2&iname=$3 RewriteRule item_(.*)/(.*).htm$ catalog.php?item=$1&iname=$2
-
Open the openinfo.php file in the /enc/ folder.
-
Find the code:
if ($category) { -
A little further down, find the code:
$metarow = mysql_fetch_array($metaresult);
-
Just under that code, add:
// START ERROR IF CATEGORY NAME IS INCORRECT if(isset($_GET['cname']) AND $_GET['cname']!=formatLinkNames($metarow[Category])) { header("HTTP/1.0 404 Not Found"); @header ("location: $URL/error.$pageext"); exit(); } // END ERROR IF CATEGORY NAME IS INCORRECT -
Find the code:
if ($item) { -
A little further down, find the code:
$metarow = mysql_fetch_array($metaresult);
-
Just under that code, add:
// START ERROR IF ITEM NAME IS INCORRECT if(isset($_GET['iname']) AND $_GET['iname']!=formatLinkNames($metarow[Item])) { header("HTTP/1.0 404 Not Found"); @header ("location: $URL/error.$pageext"); exit(); } // END ERROR IF ITEM NAME IS INCORRECT -
Save and reload both files.
Please note: This modification can cause some links to fail if there are non alpha-numeric characters in the item or category name. Please make sure to test all links thoroughly before launching after applying this modification.