Webmaster Hub: URL rewriting - Webmaster Hub

Aller au contenu

Page 1 sur 1
  • Vous ne pouvez pas commencer un sujet
  • Vous ne pouvez pas répondre à ce sujet

URL rewriting Question d'ordre Noter : -----

#1 L'utilisateur est hors-ligne   Patotoche65 

  • Groupe : Membre
  • Messages : 77
  • Inscrit(e) : 09-mai 04
  • Localisation:Devant un écran

Posté 09 mai 2004 - 17:06

Bonjour à tous,

Et oui, un p'tit nouveau .... :D

Une question me travaille au sujet de l'url rewriting.

Je me lance dans le rewriting (j'ai regardé le tuto... ) et la, je crois que les 2 seules neurrones qui me restent sont en train de partir en courant.

J'explique :

Sur mon site les url sont comme ceci : http://www.monsite.c...ex.php?cPath=87 ou http://www.monsite.c...php?cPath=87_27 ou encore http://www.monsite.com/product_info.php?cP...&products_id=94

J'ai mis dans le .htaccess (pour la première forme d'Url)

Citation

Citation:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^produit-([0-9]+)\.html$ index.php?cPath=$1 [L]



Donc, lorsque l'on tape http://www.monsite.c...duit-xxxxx.html , on va à l'adresse php correspondante. OK, mais il ne faudrais faire l'inverse ? Pour le référencement ?

Dans l'exemple ci dessus, personne ne peut connaître l'existence de cette adresse, elle n'est déclarée nulle part ......

Les seules adresses de mon site sont du type php .....

Merci
0

#2 L'utilisateur est hors-ligne   Berberber 

  • webmaster
  • Groupe : Hubmaster
  • Messages : 827
  • Inscrit(e) : 22-mars 04
  • Localisation:Warszawa

Posté 09 mai 2004 - 17:16

cela fait partie du truc, il faut les changer ces adresses, pour les faire correspondre aux nouvelles
0

#3 L'utilisateur est hors-ligne   Patotoche65 

  • Groupe : Membre
  • Messages : 77
  • Inscrit(e) : 09-mai 04
  • Localisation:Devant un écran

Posté 09 mai 2004 - 17:26

Ok, merci j'y vois plus clair ...

Donc il faut partir du html pour arriver sur du php (si je peux m'exprimer ainsi ...) et non pas l'inverse ?

Merci
0

#4 L'utilisateur est hors-ligne   Dan 

  • Webmaster
  • Voir le blog
  • Voir la galerie
  • Groupe : Direction
  • Messages : 22 945
  • Inscrit(e) : 18-août 03
  • Genre:Homme
  • Localisation:St Anne, Alderney
  • Société:Webmaster Hub Ltd.

Posté 09 mai 2004 - 17:31

Salut Patotoche, et bienvenue à bord.

Ce que tu mentionnes relève de la mauvaise compréhension assez classique de ceux qui s'attaquent à la réécriture d'URL.
Il faut impérativement que dans tes sources de programme, tous les liens soient sous la forme produit-xxx.html et non plus index.php?cPath=xxx.
Tu es donc dans l'obligation de raisonner "à l'envers" et de prévoir quel sera le format d'URLs que tu veux montrer au public.

Aucune règle de réécriture ne te permettra d'automatiser cela comme ces liens sont générés dans tes sources de programmes. A toi donc de te retrousser les manches et de modifier ton code.
Une fois le code modifié, c'est alors que la réécriture pourra être envisagée et que tu verras un gain important au niveau de l'indexation dans les moteurs, pas avant.

Cordialement,

Dan
La théorie, c'est quand on sait tout et que rien ne fonctionne. La pratique, c'est quand tout fonctionne et que personne ne sait pourquoi.
Si la pratique et la théorie sont réunies, rien ne fonctionne et on ne sait pas pourquoi. - Albert Einstein -
Infogérance de serveurs dédiés OVH
0

#5 L'utilisateur est hors-ligne   Patotoche65 

  • Groupe : Membre
  • Messages : 77
  • Inscrit(e) : 09-mai 04
  • Localisation:Devant un écran

Posté 09 mai 2004 - 17:37

Super merci,

Avec une simple phrase, je comprends tout.

Ok, je m'y colle avec les manches retroussées :D

A++
0

#6 L'utilisateur est hors-ligne   Patotoche65 

  • Groupe : Membre
  • Messages : 77
  • Inscrit(e) : 09-mai 04
  • Localisation:Devant un écran

Posté 11 mai 2004 - 10:24

Bon OK A YE,

Je suis en train de travailler sur du rewriting.

Il me faudrais un coups de pouce pour du php car je suis une buse.

Donc, voici le sujet :
Dans le code suivant, les url sont transformées du format suivant

Citation


dans le format suivant :

Citation


Par contre, il me faudrais un .html derrière (ce doit être simple mais la je vois pas .... ) pour que l'url soit de cette forme (pour info, le .htaccess fonctionne bien):

Citation


Voici le code en question :

Citation

  include('includes/application_top.php');
  if ($REQUEST_URI == '') {
    tep_redirect(tep_href_link(FILENAME_DEFAULT));
  }

  if ($REQUEST_TYPE == 'SSL') {
    $comparison_array = explode('/', HTTPS_SERVER . DIR_WS_HTTPS_CATALOG, 4);
  } else {
    $comparison_array = explode('/', HTTP_SERVER . DIR_WS_HTTP_CATALOG, 4);
  }
  $comparison = $comparison_array[3];

  $parts = explode('?', str_replace($comparison, '', $REQUEST_URI), 2);
  $list = explode('/', preg_replace(array('#^/#', '#/$#'), '', $parts[0]));
  if (sizeof($parts) == 2) {
    $parameters = explode('&', $parts[1]);
    foreach ($parameters as $pair) {
      $pieces = explode('=', $pair);
      $HTTP_GET_VARS[$pieces[0]] = $pieces[1];
    }
  }
  $current_category_id = 0;
  $cPath_array = array();
  $count = 0;
  foreach ($list as $piece_encoded) {
    $count++;
    $piece = urldecode(preg_replace(array('/[+]/', '/%20/'), array(' ', '%2F'), $piece_encoded));
    if ($piece == 'catalog') {
      continue;
    }
    $query_string = "select cd.categories_id from categories_description cd, categories c where cd.categories_id=c.categories_id and cd.categories_name='" . tep_db_input($piece) ."' and c.parent_id='" . (int)$current_category_id . "'";
    $category_query = tep_db_query("select cd.categories_id from categories_description cd, categories c where cd.categories_id=c.categories_id and cd.categories_name='" . tep_db_input($piece) ."' and c.parent_id='" . (int)$current_category_id . "'");
    if ($category_array = tep_db_fetch_array($category_query)) {
      $cPath_array[]= $category_array['categories_id'];
      $breadcrumb->add($piece, tep_href_link(FILENAME_DEFAULT, 'cPath=' . implode('_', $cPath_array)));
      $current_category_id = $category_array['categories_id'];
    } else {
      if ($current_category_id != '0') {
        $parent_where_string = " and p2c.categories_id='" . (int)$current_category_id . "'";
      } else {
        $parent_where_string = '';
      }
      $product_query = tep_db_query("select pd.products_id from products_description pd, products_to_categories p2c, products p where p.products_id = pd.products_id and p.products_status = '1' and pd.products_id=p2c.products_id and pd.products_name='" . tep_db_input($piece) ."'" . $parent_where_string);
      if ($product_array = tep_db_fetch_array($product_query)) {
        if (sizeof($cPath_array) < 1) {
          $cPath = tep_get_product_path($product_array['products_id']);
          $cPath_array = explode('_', $cPath);
          for ($i=0, $n=sizeof($cPath_array); $i<$n; $i++) {
            $categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$cPath_array[$i] . "' and language_id = '" . (int)$languages_id . "'");
            if (tep_db_num_rows($categories_query) > 0) {
              $categories = tep_db_fetch_array($categories_query);        $breadcrumb->add($categories['categories_name'], tep_href_link(FILENAME_DEFAULT, 'cPath=' . implode('_', array_slice($cPath_array, 0, ($i+1)))));
            } else {
              break;
            }
          }
        } else {
          $cPath = implode('_', $cPath_array);
        }
        $breadcrumb->add($piece, tep_href_link(FILENAME_PRODUCT_INFO, 'cPath=' . $cPath . '&products_id=' . $product_array['products_id']));
        $HTTP_GET_VARS['products_id'] = $product_array['products_id'];
        $PHP_SELF_REWRITE = dirname($PHP_SELF) . '/' . FILENAME_PRODUCT_INFO;
$PHP_SELF = $PHP_SELF_REWRITE;
        include(FILENAME_PRODUCT_INFO);
        exit();
      } else {
        $manufacturer_query = tep_db_query("select manufacturers_id from manufacturers where manufacturers_name='" . tep_db_input($piece) ."'");
        if ($manufacturer_array = tep_db_fetch_array($manufacturer_query)) {
          $breadcrumb->add($piece, tep_href_link(FILENAME_DEFAULT, 'cPath=' . implode('_', $cPath_array) . 'manufacturers_id=' . (int)$manufacturers_array['manufacturers_id']));
          $HTTP_GET_VARS['manufacturers_id'] = $manufacturer_array['manufacturers_id'];
          if ($count == sizeof($list)) {
            $HTTP_GET_VARS['filter_id'] = $current_category_id;
            $PHP_SELF_REWRITE = dirname($PHP_SELF) . '/' . FILENAME_DEFAULT;
    $PHP_SELF = $PHP_SELF_REWRITE;
            $cPath = implode('_', $cPath_array);
            $HTTP_GET_VARS['cPath'] = $cPath;
            include(FILENAME_DEFAULT);
            exit();
          }
        } else {
          reset($list);
          tep_redirect(tep_href_link(FILENAME_ADVANCED_SEARCH_RESULT, 'keywords=' . implode('+', $list)));
        }
      }
    }
  }
  $cPath = implode('_', $cPath_array);
  $HTTP_GET_VARS['cPath'] = $cPath;
  $PHP_SELF_REWRITE = dirname($PHP_SELF) . '/' . FILENAME_DEFAULT;
  $PHP_SELF = $PHP_SELF_REWRITE;
  include(FILENAME_DEFAULT);
 
?>


Merci à vous,

Patotoche65
0

#7 L'utilisateur est hors-ligne   Anonymus 

  • Groupe : Hubmaster
  • Messages : 5 139
  • Inscrit(e) : 26-août 03
  • Genre:Homme
  • Localisation:Normandie.. (pas loin de Paris)
  • Société:L'atelier des Chefs

Posté 11 mai 2004 - 10:56

Bonjour,

pour changer les liens sur un site os commerce, il te faut faire les manipulations dans le fichier
/catalogue/includes/functions/html_output.php.

Là, tu trouveras la 'formule' permettant de 'construire' un lien, avec différents paramètres, différentes options possibles.

Pour info, les liens concernant la partie 'admin' se trouvent dans le répertoire :
./catalogue/admin/includes/functions/html_output.php

Anonymus.
0

#8 L'utilisateur est hors-ligne   Patotoche65 

  • Groupe : Membre
  • Messages : 77
  • Inscrit(e) : 09-mai 04
  • Localisation:Devant un écran

Posté 11 mai 2004 - 11:11

Merci Anonymus,

Mais avec mon niveau en php, j'y vois pas grand chose ..... :blush:
Voici les modifs faites dans le fichier /catalogue/includes/functions/html_output.php.

Citation

    $separator = '?';
    if (tep_not_null($parameters)) {
      $product_name = '';
      switch ($page) {
        case FILENAME_PRODUCT_INFO:
        case FILENAME_DEFAULT:
          $manufacturer_name = '';
          $product_name = '';
          $new_parameter_list = array();
          $cPath_list = array();
          foreach (explode('&', $parameters) as $pair) {
            global $languages_id;
            $pair_array = explode('=', $pair);
            switch ($pair_array[0]) {
              case 'action':
                $link .= $page . '?' . tep_output_string($parameters);
                $separator = '&';
                break 3;
              case 'cPath':
                $parent_id = 0;
                foreach (explode('_', $pair_array[1]) as $category_id) {
                  $category_name_query = tep_db_query("select cd.categories_name from categories_description cd, categories c where cd.categories_id=c.categories_id and cd.categories_id='" . (int)$category_id . "' and cd.language_id='" . (int)$languages_id . "' and c.parent_id='" . (int)$parent_id . "'");
                  if ($category_name_array = tep_db_fetch_array($category_name_query)) {
                    $cPath_list[]= urlencode($category_name_array['categories_name']);
                    $parent_id = $category_id;
                  }
                }
                break;
              case 'products_id':
                $product_name_query = tep_db_query("select products_name from products_description where products_id='" . (int)$pair_array[1] . "' and language_id='" . (int)$languages_id . "'");
                if ($product_name_array = tep_db_fetch_array($product_name_query)) {
                  $product_name = $product_name_array['products_name'];
                }
                break;
              case 'manufacturers_id':
                $manufacturer_name_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id='" . (int)$pair_array[1] . "'");
                if ($manufacturer_array = tep_db_fetch_array($manufacturer_name_query)) {
                  $manufacturer_name = $manufacturer_array['manufacturers_name'];
                }
                break;
              case '':
                break;
              default:
                if (tep_not_null($pair)) $new_parameter_list[]= $pair;
            }
          }
          if (tep_not_null($manufacturer_name)) {
            $cPath_list[]= urlencode($manufacturer_name);
          }
          if (tep_not_null($product_name)) {
            $cPath_list[]= urlencode($product_name);
          }
          $separator = '?';
          $link .= preg_replace('/%2F/', '%20', implode('/', $cPath_list));
          if (tep_not_null($new_parameter_list)) {
            $link .= $separator . implode('&', $new_parameter_list);
            $separator = '&';
          }
          break;
        default:
          $link .= $page . '?' . tep_output_string($parameters);
          $separator = '&';
      }
    } else {
      $link .= $page;
      $separator = '?';
    }


Mais comment faire pour y mettre un .html derrière ? vois pô ...

Merci
0

Partager ce sujet :


Page 1 sur 1
  • Vous ne pouvez pas commencer un sujet
  • Vous ne pouvez pas répondre à ce sujet

1 utilisateur(s) en train de lire ce sujet
0 membre(s), 1 invité(s), 0 utilisateur(s) anonyme(s)