Should work with all versions of ultimate seo urls (Using -c- -m- etc)
Corrects bad links and 301 redirects to good link. (Good practice as Google will update its index acordingly)
Now 404 redirects to index.php if the page no longer exists (e.g. a deleted category or product etc.).
Less code in application_top.php (Moves some to includes/functions/general.php as a tep function)
### instructions ###
catalog/includes/application_top.php
Find ...
// Ultimate SEO URLs v2.1
include_once(DIR_WS_CLASSES . 'seo.class.php');
if ( !is_object($seo_urls) ){
$seo_urls = new SEO_URL($languages_id);
}
Add immediately below: -
################################################
// fwrmedia.co.uk mod to check SEO link validity
if ( is_object($seo_urls) && strpos($_SERVER['REQUEST_URI'], '.html') ) { // SEO URLS is active and there is .html in the querystring
tep_validate_seo_urls();
}
################################################
// END fwrmedia.co.uk mod to check SEO link validity
catalog/includes/functions/general.php
Add immediately above the final closing ?> at the bottom of the file
function tep_validate_seo_urls() {
global $validate_array, $HTTP_GET_VARS;
################################################
// fwrmedia.co.uk mod to check SEO link validity
$seo_request = preg_replace("/([&]|)osCsid=.{32}/", "", $_SERVER['REQUEST_URI']); // Lose the osCsid
$added_uri = strstr ( $seo_request, '?' ); // any extras in the querystring? like page=x&sort=y (split_page_results)
( strpos($_SERVER['REQUEST_URI'], '-p-') ? ($querytype = 'filename_product_info-products_id=' . $HTTP_GET_VARS['products_id']) :
( strpos($_SERVER['REQUEST_URI'], '-c-') ? ($querytype = 'filename_default-cPath=' . $HTTP_GET_VARS['cPath']) :
( strpos($_SERVER['REQUEST_URI'], '-m-') ? ($querytype = 'filename_default-manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id']) :
( strpos($_SERVER['REQUEST_URI'], '-pi-') ? ($querytype = 'filename_popup_image-pID=' . $HTTP_GET_VARS['pID']) :
( strpos($_SERVER['REQUEST_URI'], '-t-') ? ($querytype = 'filename_articles-tPath=' . $HTTP_GET_VARS['pID']) :
( strpos($_SERVER['REQUEST_URI'], '-a-') ? ($querytype = 'filename_article_info-articles_id=' . $HTTP_GET_VARS['articles_id']) :
( strpos($_SERVER['REQUEST_URI'], '-pr-') ? ($querytype = 'filename_product_reviews-products_id=' . $HTTP_GET_VARS['products_id']) :
( strpos($_SERVER['REQUEST_URI'], '-pri-') ? ($querytype = 'filename_product_reviews_info-products_id=' . $HTTP_GET_VARS['products_id']) :
( strpos($_SERVER['REQUEST_URI'], '-prw-') ? ($querytype = 'filename_product_reviews_write-products_id=' . $HTTP_GET_VARS['products_id']) :
( strpos($_SERVER['REQUEST_URI'], '-i-') ? ($querytype = 'filename_information-info_id=' . $HTTP_GET_VARS['info_id']) :
false ))))))))) );
$validate_array = explode('-', $querytype);
$linkreturned = tep_href_link(constant(strtoupper($validate_array[0])), $validate_array[1]) . $added_uri; // Get seo.class.php to make us a brand new url
$linktest = str_replace(HTTP_SERVER . '/', '', $linkreturned); // Pair the url down to the querystring
if (strpos($linktest, '-') === 0) { // If the link returned by seo.class.php has no text mysite.com/-c-xxx.html
$dohome = HTTP_SERVER; // It means that the page no longer exists (assuming the class is working)
header("HTTP/1.0 404 Not Found"); // Set header 404 Not Found
header("Location: $dohome"); // .. 404 redirect to index.php .. and never come back!!!
exit;
}
if ( HTTP_SERVER . $_SERVER['REQUEST_URI'] != $linkreturned ) { // Link looks bad so 301
header("HTTP/1.0 301 Moved Permanently"); // redirect to the good version
header("Location: $linkreturned"); // 301 redirect
exit;
}
################################################
// END fwrmedia.co.uk mod to check SEO link validity
}
There are some instructions on how to do this. in the easypopulate.php file around line 250 under BEGIN Define Custom Fields for your products database