Forum per Webmaster e Seo

Versione completa: Mod Rewrite per forum phpbb
Sta attualmente guardando una versione leggera del Forum. Guarda la versione completa per una corretta formattazione.
Mod Rewrite per forum phpbb

Ecco preso da una guida inglese come effettuare il Mod_Rewrite ad un forum phpbb e per i moduli aggiuntivi e renderlo appetibile ai motori di ricerca tipo google.


##########################################
#-----[ APRI ]------------------------------------------
#

includes/page_header.php

#
#-----[ CERCA]------------------------------------------
#

//
// gzip_compression
//
$do_gzip_compress = FALSE;
if($board_config['gzip_compress'])
{
   $phpver = phpversion();

   if($phpver >= "4.0.4pl1")
      {
         if(extension_loaded("zlib"))
      {
   if (headers_sent() != TRUE)
      {
         $gz_possible = isset($HTTP_SERVER_VARS["HTTP_ACCEPT_ENCODING"]) && eregi("gzip, deflate",$HTTP_SERVER_VARS["HTTP_ACCEPT_ENCODING"]);
         if ($gz_possible) ob_start("ob_gzhandler");
      }
   }
      }
         else if($phpver > "4.0")
      {
         if(strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip'))
         {
            if(extension_loaded("zlib"))
         {
            $do_gzip_compress = TRUE;
            ob_start();
            ob_implicit_flush(0);

            header("Content-Encoding: gzip");
         }
      }
   }
}

#
#-----[ SOSTITUISCI CON  ]------------------------------------------
#

//
// Begin keyword urls mod
//

ob_start();


function make_url_friendly($url)
{

   $url = strtolower($url);

   // Fix for most recent topics block
   // or else a b is shown in every url
   $find = array('<b>',
      '</b>');
   $url = str_replace ($find, '', $url);

   $find = array(' ',
      '&quot;',
      '&',
      '\r\n',
      '\n',
      '/',
      '\\',
      '+',
      '<',
      '>');
   $url = str_replace ($find, '-', $url);

   $find = array('é',
      'è',
      'ë',
      'ê',
      'É',
      'È',
      'Ë',
      'Ê');
   $url = str_replace ($find, 'e', $url);

   $find = array('í',
      'ì',
      'î',
      'ï',
      'Í',
      'Ì',
      'Î',
      'Ï');
   $url = str_replace ($find, 'i', $url);

   $find = array('ó',
      'ò',
      'ô',
      'Ó',
      'Ò',
      'Ô');
   $url = str_replace ($find, 'o', $url);

   $find = array('ö',
       'Ö');
   $url = str_replace ($find, 'oe', $url);

   $find = array('á',
      'à',
      'â',
      'Á',
      'À',
      'Â');
   $url = str_replace ($find, 'a', $url);

   $find = array('ä',
       'Ä');
   $url = str_replace ($find, 'ae', $url);

   $find = array('ú',
      'ù',
      'û',
      'Ú',
      'Ù',
      'Û');
   $url = str_replace ($find, 'u', $url);

   $find = array('ü',
       'Ü');
   $url = str_replace ($find, 'ue', $url);

   $find = array('ß');
   $url = str_replace ($find, 'ss', $url);

   $find = array('/[^a-z0-9\-<>]/',
      '/[\-]+/',
      '/<[^>]*>/');

   $repl = array('',
      '-',
      '');

   $url =  preg_replace ($find, $repl, $url);

   $url = str_replace ('--', '-', $url);

   return $url;
}



function rewrite_urls($content)
{

   function if_query($amp)
   {

      if($amp != '')
      {
         return '?';
      }

   }

   $url_in = array('/(?<!\/)viewforum.php\?f=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)\.\/viewforum.php\?f=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)viewtopic.php\?p=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)viewtopic.php\?t=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)album_cat.php\?cat_id=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)album_thumbnail.php\?pic_id=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)album_pic.php\?pic_id=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)album_picm.php\?pic_id=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)album_showpage.php\?pic_id=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(<img .*?)<\/a>/e',
         '/(?<!\/)album_showpage.php\?full=&pic_id=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(<img .*?)<\/a>/e',
         '/(?<!\/)album_showpage.php\?pic_id=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)album_personal.php\?user_id=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)dload.php\?action=category&cat_id=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)dload.php\?action=file&file_id=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)kb.php\?mode=cat&cat=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)kb.php\?mode=article&k=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)kb.php\?mode=stats&stats=mostpopular((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)kb.php\?mode=stats&stats=toprated((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)kb.php\?mode=stats&stats=latest((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)press.php\?mode=cat&cat=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)press.php\?mode=article&k=([0-9]+)((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)press.php\?mode=stats&stats=mostpopular((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)press.php\?mode=stats&stats=toprated((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)press.php\?mode=stats&stats=latest((&amp;)|(&)){0,1}([^>]+>)(.*?)<\/a>/e');

   $url_out = array("make_url_friendly('\\6') . '-vf\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-vf\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-vp\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-vt\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-ac\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-at\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-apic\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-apm\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "'show-pic-asp\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "'show-pic-full-asp\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-asp\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-aper\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-dc\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-df\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-kbc\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-kba\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\5') . '-kbsmp.html' . if_query('\\1') . stripslashes('\\4\\5') . '</a>'",
         "make_url_friendly('\\5') . '-kbstr.html' . if_query('\\1') . stripslashes('\\4\\5') . '</a>'",
         "make_url_friendly('\\5') . '-kbsl.html' . if_query('\\1') . stripslashes('\\4\\5') . '</a>'",
         "make_url_friendly('\\6') . '-pc\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\6') . '-pa\\1.html' . if_query('\\2') . stripslashes('\\5\\6') . '</a>'",
         "make_url_friendly('\\5') . '-psmp.html' . if_query('\\1') . stripslashes('\\4\\5') . '</a>'",
         "make_url_friendly('\\5') . '-pstr.html' . if_query('\\1') . stripslashes('\\4\\5') . '</a>'",
         "make_url_friendly('\\5') . '-psl.html' . if_query('\\1') . stripslashes('\\4\\5') . '</a>'");

   $content = preg_replace($url_in, $url_out, $content);

   return $content;

}

//
// end keyword urls mod
//

#
#-----[ APRI ]------------------------------------------
#

includes/page_tail.php

#
#-----[ CERCA ]------------------------------------------
#

if ( $do_gzip_compress )
{
   //
   // Borrowed from php.net!
   //
   $gzip_contents = ob_get_contents();
   ob_end_clean();

   $gzip_size = strlen($gzip_contents);
   $gzip_crc = crc32($gzip_contents);

   $gzip_contents = gzcompress($gzip_contents, 9);
   $gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);

   echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
   echo $gzip_contents;
   echo pack('V', $gzip_crc);
   echo pack('V', $gzip_size);
}

#
#-----[ SOSTITUISCI CON  ]------------------------------------------
#

//
// begin keyword urls mod
//

header ('Expires: 0');
header ('Pragma: no-cache');
header ('X-Powered-By:');
header ('Server:');

if( function_exists(ob_gzhandler) && $board_config['gzip_compress'] == 1)
{
   $gzip_contents = rewrite_urls(ob_get_contents());

   ob_end_clean();
   ob_start('ob_gzhandler');

   echo $gzip_contents;

   Header('Vary: Accept-Encoding');
//   header('Content-Length: '.ob_get_length());
//   Header('X-Content-Original-Length: ' . strlen($gzip_contents));
   Header('X-Content-Encoded-By: webmedic page zipper');

   ob_end_flush();
}
else
{
   $contents = ob_get_contents();
   ob_end_clean();
   echo rewrite_urls($contents);
   global $dbg_starttime;
}

//
// end keyword urls mod
//


#
#-----[ APRI]------------------------------------------
#

.htaccess

#
#-----[ AGGIUNGI  ]------------------------------------------
#

Options +FollowSymlinks

RewriteEngine On
#elimina /forum/ se è nella root o cambialo con il nome della tua cartella dove è installato lo script
RewriteBase /forum/

RewriteRule [.]*-vf([0-9]*) viewforum.php?%{QUERY_STRING}&f=$1
RewriteRule [.]*-vp([0-9]*) viewtopic.php?%{QUERY_STRING}&p=$1
RewriteRule [.]*-vt([0-9]*) viewtopic.php?%{QUERY_STRING}&t=$1
RewriteRule [.]*-vc([0-9]*) index.php?%{QUERY_STRING}&c=$1
RewriteRule [.]*-ac([0-9]*) album_cat.php?%{QUERY_STRING}&cat_id=$1
RewriteRule [.]*-at([0-9]*) album_thumbnail.php?%{QUERY_STRING}&pic_id=$1
RewriteRule [.]*-apic([0-9]*) album_pic.php?%{QUERY_STRING}&pic_id=$1
RewriteRule [.]*-apm([0-9]*) album_picm.php?%{QUERY_STRING}&pic_id=$1
RewriteRule [.]*-full-asp([0-9]*) album_showpage.php?full=&pic_id=$1
RewriteRule [.]*-asp([0-9]*) album_showpage.php?%{QUERY_STRING}&pic_id=$1
RewriteRule [.]*-aper([0-9]*) album_personal.php?%{QUERY_STRING}&user_id=$1
RewriteRule [.]*-dc([0-9]*) dload.php?%{QUERY_STRING}action=category&cat_id=$1
RewriteRule [.]*-df([0-9]*) dload.php?%{QUERY_STRING}action=file&file_id=$1
RewriteRule [.]*-kbc([0-9]*) kb.php?%{QUERY_STRING}mode=cat&cat=$1
RewriteRule [.]*-kba([0-9]*) kb.php?%{QUERY_STRING}mode=article&k=$1
RewriteRule [.]*-kbsmp kb.php?mode=stats&stats=mostpopular
RewriteRule [.]*-kbstr kb.php?mode=stats&stats=toprated
RewriteRule [.]*-kbsl kb.php?mode=stats&stats=latest
RewriteRule [.]*-pbc([0-9]*) kb.php?%{QUERY_STRING}mode=cat&cat=$1
RewriteRule [.]*-pa([0-9]*) kb.php?%{QUERY_STRING}mode=article&k=$1
RewriteRule [.]*-psmp kb.php?mode=stats&stats=mostpopular
RewriteRule [.]*-pstr kb.php?mode=stats&stats=toprated
RewriteRule [.]*-pbsl kb.php?mode=stats&stats=latest

##########################################




Coming Soon - passate più tardi ;) **(da testare)** se qualcuno lo prova mi faccia uno squillo :p (cioè posti sotto)
Io l'ho messo, ma cosa dovrei notare di diverso?
dovrebbe rendere le url statiche dalle url dinamiche del forum phpbb

(fa un backup dei file prima di apportare qualsiasi modifica)
Infatti l'avevo fatto e ho dovuto rimettere gli stessi file perché con il mio forum quetsa mod non va d'accordo.

Peccato! Sad
ma l'hai creato il file .htaccess ed hai fatto l'upload ?
Si l'ho creato ma niente lo stesso. Poi ho chiesto nel forum della mia board e mi hanno risposto che per metter il mod_rewrite al mio forum devo installare una mod a parte che ci vogliono due ore per finirla.

Che mazzata!!! Sad
sinceramente ti consiglierei mybboard (il forum che vedi qui...) poi ci sarà un tool per passare i dati del db da phpbb a mybb.
Apportando alcune modifiche e correggendo un errore che ho fatto e di cui non mi sono reso conto prima, il mod_rewrite funziona perfettamente almeno per quando riguarda i topic.

Comunque lo sto testando per vedere se escono fuori problemi.

Ciao!!! Wink
ok, poi fammi sapere cosa hai fatto ... i procedimenti e come va... gentilmente, in modo che se qualcuno lo vuole sfruttare, lo può fare tranquillamente.
La modifica che ho fatto è stata eliminare questa parte di codice nuovo dal file include/page_header.php

Codice:
'/(?<!\/)album_cat.php\?cat_id=([0-9]+)((&)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)album_thumbnail.php\?pic_id=([0-9]+)((&)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)album_pic.php\?pic_id=([0-9]+)((&)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)album_picm.php\?pic_id=([0-9]+)((&)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)album_showpage.php\?pic_id=([0-9]+)((&)|(&)){0,1}([^>]+>)(<img .*?)<\/a>/e',
         '/(?<!\/)album_showpage.php\?full=&pic_id=([0-9]+)((&)|(&)){0,1}([^>]+>)(<img .*?)<\/a>/e',
         '/(?<!\/)album_showpage.php\?pic_id=([0-9]+)((&)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',
         '/(?<!\/)album_personal.php\?user_id=([0-9]+)((&)|(&)){0,1}([^>]+>)(.*?)<\/a>/e',


Poi eliminare quest'altro dal file .htaccess:

Codice:
RewriteRule [.]*-ac([0-9]*) album_cat.php?%{QUERY_STRING}&cat_id=\
RewriteRule [.]*-at([0-9]*) album_thumbnail.php?%{QUERY_STRING}&pic_id=\
RewriteRule [.]*-apic([0-9]*) album_pic.php?%{QUERY_STRING}&pic_id=\
RewriteRule [.]*-apm([0-9]*) album_picm.php?%{QUERY_STRING}&pic_id=\
RewriteRule [.]*-full-asp([0-9]*) album_showpage.php?full=&pic_id=\
RewriteRule [.]*-asp([0-9]*) album_showpage.php?%{QUERY_STRING}&pic_id=\
RewriteRule [.]*-aper([0-9]*) album_personal.php?%{QUERY_STRING}&user_id=\


Questo perchè nel mio forum phpBB2 Orion creava problemi.

Per il resto sembri funzionare.

Solo una cosa, i link delle categorie nella home del forum non vengono cambiati, internamente invece funzionano.

Topic e messaggi tutto bene.


Ciao!!!

URL di riferimento