> Manuales > Manual de OsCommerce

Cómo modificar las direcciones web por defecto de OsCommerce por páginas terminadas en .html y con el nombre del producto.

Esta contribución de Chemo , es de las que más útiles que he encontrado.

Modifica las direcciones web por defecto de OsCommerce por páginas terminadas en .html y con el nombre del producto, es decir, sustituye el http://www.tudominio.com/product_info.php?products_id=207 por http://www.tudominio.com/tijerasdepunta.html

Esto hace que tu tienda se indexe mejor en los buscadores.

Primero que nada descargamos la última versión de la contribución ,SEO URL´s y descomprimimos.

Luego tenemos que subir a nuestro servidor los archivos siguientes:

includes/classes/seo.class.php y admin/includes/reset_seo_cache.php

Editamos includes/application_top.php

Justo después de este código :

// include the language translations

require(DIR_WS_LANGUAGES . $language . '.php');

Añadimos:
// 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);
}

Ahora editamos includes/functions/html_output.php y reemplazamos el siguiente código :

////
// The HTML href link wrapper function

function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {
    global $request_type, $session_started, $SID;
   if (!tep_not_null($page)) {
      die('<br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine the page link!<br><br>');
    }
   if ($connection 'NONSSL') {
       $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
    } elseif ($connection ‘SSL’) {
       if (ENABLE_SSL true) {
          $link = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG;
       } else {
          $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
      }
    } else {
       die('<br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine connection method on a link!<br><br>Known methods: NONSSL SSL</b><br><br>');
    }
   if (tep_not_null($parameters)) {
      $link .= $page . '?' . tep_output_string($parameters);
       $separator = '&';
    } else {
      $link .= $page; $separator = '?';
    }
   while ( (substr($link, -1) ‘&’) || (substr($link, -1) '?') )
    $link = substr($link, 0, -1);
// Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined

if ( ($add_session_id true) &&($session_started true) && (SESSION_FORCE_COOKIE_USE ‘False’) ) {
    if (tep_not_null($SID)) {
       $_sid = $SID;
    } elseif ( ( ($request_type 'NONSSL') && ($connection ‘SSL’) && (ENABLE_SSL true) ) || ( ($request_type ‘SSL’) && ($connection 'NONSSL') ) ) {
       if (HTTP_COOKIE_DOMAIN != HTTPS_COOKIE_DOMAIN) {
          $_sid = tep_session_name() . '=' . tep_session_id();
      }
    }
}
if ( (SEARCH_ENGINE_FRIENDLY_URLS ‘true’) && ($search_engine_safe == true) ) {
   while (strstr($link, ‘&&’))
      $link = str_replace(‘&&’, ‘&’, $link);
      $link = str_replace(‘?’, ‘/’, $link);
       $link = str_replace(‘&’, ‘/’, $link);
      $link = str_replace(‘=’, ‘/’, $link);
      $separator = ‘?’;
}
if (isset($_sid)) {
   $link .= $separator . $_sid;
}
return $link;
}
por

////
// Ultimate SEO URLs v2.1
// The HTML href link wrapper function

function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {
global $seo_urls;
if ( !is_object($seo_urls) ){
if ( !class_exists('SEO_URL') ){
include_once(DIR_WS_CLASSES . 'seo.class.php');
}
global $languages_id;
$seo_urls = new SEO_URL($languages_id);
}

return $seo_urls->href_link($page, $parameters, $connection, $add_session_id);

}


Ahora editamos admin/categories.php
Justo después del código:

$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');

Añadir lo siguiente:

// Ultimate SEO URLs v2.1
// If the action will affect the cache entries

if ( eregi("(insert|update|setflag)", $action) ) include_once('includes/reset_seo_cache.php');


Casi terminando ya, editamos admin/includes/functions/general.php
y justo antes del último ?> pegamos el siguiente código:

// Function to reset SEO URLs database cache entries
// Ultimate SEO URLs v2.1
function tep_reset_cache_data_seo_urls($action){
switch ($action){
case 'reset':
tep_db_query("DELETE FROM cache WHERE cache_name LIKE '%seo_urls%'");
tep_db_query("UPDATE configuration SET configuration_value='false' WHERE configuration_key='SEO_URLS_CACHE_RESET'");
break;
default:
break;
}

return 'false';
}


Ahora nos queda editar y/o crear el archivo .htacces
Editamos el .htacces, y si tenemos la tienda en un subdirectorio, es decir tudominio.com/directorio . Sustituye /directorio/ por el nombre de tu carpeta. Y pegamos:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /directorio/

RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-c-(.*).html$ index.php?cPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-m-(.*).html$ index.php?manufacturers_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pi-(.*).html$ popup_image.php?pID=$2&%{QUERY_STRING}
RewriteRule ^(.*)-t-(.*).html$ articles.php?tPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-a-(.*).html$ article_info.php?articles_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pr-(.*).html$ product_reviews.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pri-(.*).html$ product_reviews_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-i-(.*).html$ information.php?info_id=$2&%{QUERY_STRING}

Si tu tienda está en el directorio raíz, es decir tudominio.com, tenemos que pgar lo siguiente.

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-c-(.*).html$ index.php?cPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-m-(.*).html$ index.php?manufacturers_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pi-(.*).html$ popup_image.php?pID=$2&%{QUERY_STRING}
RewriteRule ^(.*)-t-(.*).html$ articles.php?tPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-a-(.*).html$ article_info.php?articles_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pr-(.*).html$ product_reviews.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pri-(.*).html$ product_reviews_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-i-(.*).html$ information.php?info_id=$2&%{QUERY_STRING}


Ahora ya puedes poner en tu navegador preferido la dirección de tu tienda, el automáticamente se pondrá en marcha!

Desde la tienda, el menú Configuración aparecerá ahora un apartado llamado SEO URL´S donde podrás configurar varios parámetros, como la activación o desactivación de estos, por categorías, échale un vistazo…

Miguelo

Fundador y director de Regaletes.com

Manual