Qu'est ce que l'url rewriting?

C'est la capacité d'un serveur a réécrire une url, voici un exemple: votre visiteur tape http://smf-fr.org/forum/board-50-0.html le serveur lui va recupérer l'url et la réécrire de la façon suivante: http://smf-fr.org/forum/index.php?board=50.0

Comment la mettre en place?

configuration du serveur

Il faut d'abord verifier que le serveur sur lequel vous vous trouvez est un serveur Apache de version egale ou supérieure à 1.3.27 .

Il faut ensuite que celui-ci est les options suivantes d'activées:

mod_rewrite

pour ceux qui ont acces au fichier httpd.conf il faut avoir ces deux lignes

LoadModule rewrite_module libexec/mod_rewrite.so
AddModule mod_rewrite.c

réalisation du fichier htaccess

Pour smf 1.1.x et uniquement pour lui voilà ce qu'il faut mettre dedans

# Le serveur doit suivre les liens symboliques :
Options +FollowSymlinks
# Activation du module de réécriture d'URL :
RewriteEngine on

#redirection des boards
RewriteRule ^board-([0-9]+)\.html$ /le_repertoire_de_votre_forum/index.php?board=$1 [L]
RewriteRule ^board-([0-9]+)-([0-9]+)\.html$ /le_repertoire_de_votre_forum/index.php?board=$1.$2 [L]

#redirection d'un topic seul
RewriteRule ^topic-([0-9]+)\.html$ /le_repertoire_de_votre_forum/index.php?topic=$1 [L]
RewriteRule ^topic-([0-9]+)-([0-9]+)\.html$ /le_repertoire_de_votre_forum/index.php?topic=$1.$2 [L]

le texte le_repertoire_de_votre_forum est à remplacer par votre repertoire actuelle. Il est possible que sur certains serveur cela ne fonctionne pas il faut enlever le / devant le_repertoire_de_votre_forum.

Les fichiers à modifiers

Le mod automatique

Les modifications qui suivent ont fait l'objet d'un mod qui permet aux novices de s'affranchir de la manipulation des fichiers, attention ce mod ne concerne que les modifications dans smf, vous devez ne pas oublier de faire le fichier .htaccess indispensable pour faire fonctionner l'UrlRewriting Vous trouverez le mod automatique ici: http://support.smfgratuit.org/Mod_UrlRewriting_V12-topic-68-0.html

Editer BoardIndex.php

Editer le fichier suivant: /sources/BoardIndex.php

rechercher

    // For wireless, we use the Wireless template...

ajouter avant

   //urlrewriting by MkC
   $scripturl2 = str_replace('index.php','',$scripturl);
   //fin urlrewriting by MkC

Rechercher

                    'href' => $scripturl . '?board=' . $row_board['ID_BOARD'] . '.0',
                    'link' => '<a href="' . $scripturl . '?board=' . $row_board['ID_BOARD'] . '.0">' . $row_board['boardName'] . '</a>'

Remplacer par

           //urlrewriting by MkC
           'href' => $scripturl2 . 'board-' . $row_board['ID_BOARD'] . '-0.html',
           'link' => '<a href="' . $scripturl2 . 'board-' . $row_board['ID_BOARD'] . '-0.html">' . $row_board['boardName'] . '</a>'
           //fin urlrewriting by mkc

Rechercher

                'href' => $scripturl . '?board=' . $row_board['ID_BOARD'] . '.0',
                'link' => '<a href="' . $scripturl . '?board=' . $row_board['ID_BOARD'] . '.0">' . $row_board['boardName'] . '</a>'

remplacer par

        //urlrewriting by MkC
        'href' => $scripturl2 . 'board-' . $row_board['ID_BOARD'] . '-0.html',
        'link' => '<a href="' . $scripturl2 . 'board-' . $row_board['ID_BOARD'] . '-0.html">' . $row_board['boardName'] . '</a>'
        //fin urlrewriting by mkc

Editer Display.php

Editer le fichier suivant: /Sources/Display.php

Rechercher

    // What are you gonna display if these are empty?!

Ajouter avant

   //urlrewriting by MkC
   $scripturl2 = str_replace('index.php','',$scripturl);
   //fin urlrewriting by MkC

Rechercher

    $context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%d', $_REQUEST['start'], $topicinfo['numReplies'] + 1, $modSettings['defaultMaxMessages'], true);

Remplacer par

  //urlrewriting by mkc
  $context['page_index'] = constructPageIndex($scripturl2 . 'topic-' . $topic . '-' . '%d' . '.html', $_REQUEST['start'], $topicinfo['numReplies'] + 1, $modSettings['defaultMaxMessages'], true);
  //fin urlrewriting by mkc

Rechercher

    $context['links'] = array(
        'first' => $_REQUEST['start'] >= $modSettings['defaultMaxMessages'] ? $scripturl . '?topic=' . $topic . '.0' : '',
        'prev' => $_REQUEST['start'] >= $modSettings['defaultMaxMessages'] ? $scripturl . '?topic=' . $topic . '.' . ($_REQUEST['start'] - $modSettings['defaultMaxMessages']) : '',
        'next' => $_REQUEST['start'] + $modSettings['defaultMaxMessages'] < $topicinfo['numReplies'] + 1 ? $scripturl . '?topic=' . $topic. '.' . ($_REQUEST['start'] + $modSettings['defaultMaxMessages']) : '',
        'last' => $_REQUEST['start'] + $modSettings['defaultMaxMessages'] < $topicinfo['numReplies'] + 1 ? $scripturl . '?topic=' . $topic. '.' . (floor($topicinfo['numReplies'] / $modSettings['defaultMaxMessages']) * $modSettings['defaultMaxMessages']) : '',
        'up' => $scripturl . '?board=' . $board . '.0'
    );

Remplacer par

   //urlrewriting by mkc
   $context['links'] = array(
      'first' => $_REQUEST['start'] >= $modSettings['defaultMaxMessages'] ? $scripturl2 . 'topic-' . $topic . '-0.html' : '',
      'prev' => $_REQUEST['start'] >= $modSettings['defaultMaxMessages'] ? $scripturl2 . 'topic-' . $topic . '-' . ($_REQUEST['start'] - $modSettings['defaultMaxMessages']) . '.html' : '',
      'next' => $_REQUEST['start'] + $modSettings['defaultMaxMessages'] < $topicinfo['numReplies'] + 1 ? $scripturl2 . 'topic-' . $topic. '-' . ($_REQUEST['start'] + $modSettings['defaultMaxMessages']) . '.html' : '',
      'last' => $_REQUEST['start'] + $modSettings['defaultMaxMessages'] < $topicinfo['numReplies'] + 1 ? $scripturl2 . 'topic-' . $topic. '-' . (floor($topicinfo['numReplies'] / $modSettings['defaultMaxMessages']) * $modSettings['defaultMaxMessages']) . '.html' : '',
      'up' => $scripturl . '?board=' . $board . '.0'
   );
   //fin urlrewriting by mkc

Editer MessageIndex.php

Editer le fichier suivant: /Sources/MessageIndex.php

Rechercher

    if (WIRELESS)
        $context['sub_template'] = WIRELESS_PROTOCOL . '_messageindex';
    else
        loadTemplate('MessageIndex');

Ajouter avant

  //urlrewriting by mkc
  $scripturl2 = str_replace('index.php','',$scripturl);
  //fin urlrewriting by mkc

Rechercher

    // Make sure the starting place makes sense and construct the page index.
    if (isset($_REQUEST['sort']))
        $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['num_topics'], $maxindex, true);
    else
        $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%d', $_REQUEST['start'], $board_info['num_topics'], $maxindex, true);

Remplacer par

    // Make sure the starting place makes sense and construct the page index.
  //urlrewriting by mkc
  if (isset($_REQUEST['sort']))
     $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['num_topics'], $maxindex, true);
  else
     $context['page_index'] = constructPageIndex($scripturl2 . 'board-' . $board . '-' . '%d' . '.html', $_REQUEST['start'], $board_info['num_topics'], $maxindex, true);
  //fin urlrewriting by mkc

Rechercher

    $context['links'] = array(
        'first' => $_REQUEST['start'] >= $modSettings['defaultMaxTopics'] ? $scripturl . '?board=' . $board . '.0' : '',
        'prev' => $_REQUEST['start'] >= $modSettings['defaultMaxTopics'] ? $scripturl . '?board=' . $board . '.' . ($_REQUEST['start'] - $modSettings['defaultMaxTopics']) : '',
        'next' => $_REQUEST['start'] + $modSettings['defaultMaxTopics'] < $board_info['num_topics'] ? $scripturl . '?board=' . $board . '.' . ($_REQUEST['start'] + $modSettings['defaultMaxTopics']) : '',
        'last' => $_REQUEST['start'] + $modSettings['defaultMaxTopics'] < $board_info['num_topics'] ? $scripturl . '?board=' . $board . '.' . (floor(($board_info['num_topics'] - 1) / $modSettings['defaultMaxTopics']) * $modSettings['defaultMaxTopics']) : '',
        'up' => $board_info['parent'] == 0 ? $scripturl . '?' : $scripturl . '?board=' . $board_info['parent'] . '.0'
    );

Remplacer par

   //urlrewriting by MkC
   $context['links'] = array(
      'first' => $_REQUEST['start'] >= $modSettings['defaultMaxTopics'] ? $scripturl2 . 'board-' . $board . '-0.html' : '',
      'prev' => $_REQUEST['start'] >= $modSettings['defaultMaxTopics'] ? $scripturl2 . 'board-' . $board . '-' . ($_REQUEST['start'] - $modSettings['defaultMaxTopics']) . '.html' : '',
      'next' => $_REQUEST['start'] + $modSettings['defaultMaxTopics'] < $board_info['num_topics'] ? $scripturl2 . 'board-' . $board . '-' . ($_REQUEST['start'] + $modSettings['defaultMaxTopics']) .'.html' : '',
      'last' => $_REQUEST['start'] + $modSettings['defaultMaxTopics'] < $board_info['num_topics'] ? $scripturl2 . 'board-' . $board . '-' . (floor(($board_info['num_topics'] - 1) / $modSettings['defaultMaxTopics']) * $modSettings['defaultMaxTopics']) . '.html' : '',
      'up' => $board_info['parent'] == 0 ? $scripturl . '?' : $scripturl2 . 'board-' . $board_info['parent'] . '-0.html'
   );
   //fin urlrewriting by MkC

Rechercher

                    'href' => $scripturl . '?board=' . $row_board['ID_BOARD'] . '.0',
                    'link' => '<a href="' . $scripturl . '?board=' . $row_board['ID_BOARD'] . '.0">' . $row_board['name'] . '</a>'

Remplacer par

          //urlrewriting by mkc
          'href' => $scripturl2 . 'board-' . $row_board['ID_BOARD'] . '-0.html',
          'link' => '<a href="' . $scripturl2 . 'board-' . $row_board['ID_BOARD'] . '-0.html">' . $row_board['name'] . '</a>'
           //fin urlrewriting by mkc

Rechercher

                'href' => $scripturl . '?board=' . $row['ID_BOARD'] . '.0',
                'link' => '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '.0">' . $row['name'] . '</a>'

Remplacer par

        //urlrewriting by mkc
        'href' => $scripturl2 . 'board-' . $row['ID_BOARD'] . '-0.html',
        'link' => '<a href="' . $scripturl . 'board-' . $row['ID_BOARD'] . '-0.html">' . $row['name'] . '</a>'
        //fin urlrewriting by mkc

Rechercher

                    $tmppages[] = '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.' . $tmpb . '">' . $tmpa . '</a>';

Remplacer par

          //urlrewriting by mkc
          $tmppages[] = '<a href="' . $scripturl2 . 'topic-' . $row['ID_TOPIC'] . '-' . $tmpb . '.html">' . $tmpa . '</a>';
          //fin urlrewriting by mkc

Rechercher

                    'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
                    'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['firstSubject'] . '</a>'

Remplacer par

          //urlrewriting by mkc
          'href' => $scripturl2 . 'topic-' . $row['ID_TOPIC'] . '-0.html',
          'link' => '<a href="' . $scripturl2 . 'topic-' . $row['ID_TOPIC'] . '-0.html">' . $row['firstSubject'] . '</a>'
          //fin urlrewriting
 
modifications/smf11x/url_rewriting_pour_smf_1_1_x.txt · Dernière modification: le 30/11/2007 à 17:59 par mkc
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
Creative Commons License