Synthese URL rewriting

WRInaute discret
Salut le post ref et url rewriting fais plus de 9 pages

est il possible de reprendre synthétiquement ici la meilleure methode pour faire une url rewriting avec des mots simple (et comme j'y comprend rien si j'arrive a comprendre ca voiudra dire que tout le monde peu y arriver lol)

@+
 
WRInaute discret
#
#-----[ OUVRIR ]---------------------------------------------
#
includes/sessions.php

#
#-----[ TROUVER ]---------------------------------------------
# vers la ligne 139
$sql = "UPDATE " . SESSIONS_TABLE . "
SET session_user_id = $user_id, session_start = $current_time, session_time = $current_time, session_page = $page_id, session_logged_in = $login
WHERE session_id = '" . $session_id . "'
AND session_ip = '$user_ip'";

#
#-----[ REMPLACER PAR ]---------------------------------------
#
$sql_ip = $user_id == ANONYMOUS ? " AND session_ip = '$user_ip'" : '';
$sql = "UPDATE " . SESSIONS_TABLE . "
SET session_ip = '$user_ip', session_start = $current_time, session_time = $current_time, session_page = $page_id, session_logged_in = $login
WHERE session_id = '" . $session_id . "' $sql_ip
AND session_user_id = '$user_id'";

#
#-----[ TROUVER ]---------------------------------------------
# vers la ligne 186
$SID = 'sid=' . $session_id;

#
#-----[ REMPLACER PAR ]---------------------------------------
#
$SID = $user_id > 0 ? 'sid=' . $session_id : '';

#
#-----[ TROUVER ]---------------------------------------------
# vers la ligne 256
$SID = ($sessionmethod == SESSION_METHOD_GET || defined('IN_ADMIN')) ? 'sid=' . $session_id : '';

#
#-----[ REMPLACER PAR ]---------------------------------------
#
$SID = $userdata['user_id'] > 0 ? (($sessionmethod == SESSION_METHOD_GET || defined('IN_ADMIN')) ? 'sid=' . $session_id : '') : '';

#
#-----[ TROUVER ]---------------------------------------------
# vers la ligne 303
//
// If we reach here then no (valid) session exists. So we'll create a new one,
#
#-----[ AVANT, AJOUTER ]---------------------------------------
#
elseif(empty($sessiondata))
{
// try to login guest
$sql = "SELECT u.*, s.*
FROM " . SESSIONS_TABLE . " s, " . USERS_TABLE . " u
WHERE s.session_ip = '$user_ip'
AND s.session_user_id = " . ANONYMOUS . "
AND u.user_id = s.session_user_id
LIMIT 0, 1";
if ( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, 'Error doing DB query userdata row fetch', '', __LINE__, __FILE__, $sql);
}

$userdata = $db->sql_fetchrow($result);

if ( isset($userdata['user_id']) )
{
if ( $current_time - $userdata['session_time'] > 60 )
{
$sql = "UPDATE " . SESSIONS_TABLE . "
SET session_time = $current_time, session_start = $current_time, session_page = 0
WHERE session_id = '" . $userdata['session_id'] . "'";
if ( !$db->sql_query($sql) )
{
message_die(CRITICAL_ERROR, 'Error updating sessions table', '', __LINE__, __FILE__, $sql);
}
}
return $userdata;
}
}
 
WRInaute discret
puis faire un fichier htacces

RewriteEngine On
RewriteRule ^forums.* index.php
RewriteRule ^mforum([0-9]*).* forum.php$1&mark=topics
RewriteRule ^viewforum([0-9]*)-([0-9]*)-([0-9]*).* forum.php$1&topicdays=$2&start=$3
RewriteRule ^forum([0-9]*).* forum.php$1
RewriteRule ^ptopic([0-9]*).* ftopic.php$1&view=previous
RewriteRule ^ntopic([0-9]*).* ftopic.php$1&view=next
RewriteRule ^stopic([0-9]*)-([0-9]*).* ftopic.php$1&watch=topic&start=$2
RewriteRule ^utopic([0-9]*)-([0-9]*).* ftopic.php$1&unwatch=topic&start=$2
RewriteRule ^ftopic([0-9]*)-([0-9]*)-([a-zA-Z]*)-([0-9]*).* ftopic.php$1&postdays=$2&postorder=$3&start=$4
RewriteRule ^ftopic([0-9]*)-([0-9]*).* ftopic.php$1&start=$2
RewriteRule ^ftopic([0-9]*).* ftopic.php$1
RewriteRule ^ftopic([0-9]*).html ftopic.php$1&start=$2&postdays=$3&postorder=$4&highlight=$5
RewriteRule ^setopic_([0-9]*)-([a-zA-Z0-9]*).* ftopic.php$1&highlight=$2
RewriteRule ^sutra([0-9]*).* sutra.php$1
 
WRInaute discret
#
#-----[ OUVRIR ]------------------------------------------
#
includes/page_header.php


#
#-----[ TROUVER ]------------------------------------------
#
#

$template->set_filenames(array(
'overall_header' => ( empty($gen_simple_header) ) ? 'overall_header.tpl' : 'simple_header.tpl')
);

#
#-----[ APRES, AJOUTER ]------------------------------------------
#
ob_start();
function replace_mod_rewrite($s)
{
$urlin = array(
"'(?<!/)viewforum.php\?f=([0-9]*)&amp;topicdays=([0-9]*)&amp;start=([0-9]*)'",
"'(?<!/)viewforum.php\?f=([0-9]*)&amp;mark=topics'",
"'(?<!/)viewforum.php\?f=([0-9]*)'",

"'(?<!/)viewtopic.php\?t=([0-9]*)&amp;view=previous'",
"'(?<!/)viewtopic.php\?t=([0-9]*)&amp;view=next'",
"'(?<!/)viewtopic.php\?t=([0-9]*)&amp;view=newest'",
"'(?<!/)viewtopic.php\?t=([0-9]*)&(?:amp;)watch=topic&(?:amp;)start=([0-9]*)'",
"'(?<!/)viewtopic.php\?t=([0-9]*)&(?:amp;)unwatch=topic&(?:amp;)start=([0-9]*)'",
"'(?<!/)viewtopic.php\?t=([0-9]*)&amp;postdays=([0-9]*)&amp;postorder=([a-zA-Z]*)&amp;start=([0-9]*)'", "'(?<!/)viewtopic.php\?t=([0-9]*)&amp;start=([0-9]*)&amp;postdays=([0-9]*)&amp;postorder=([a-zA-Z]*)&amp;highlight=([a-zA-Z0-9]*)'",
"'(?<!/)viewtopic.php\?t=([0-9]*)&amp;start=([0-9]*)'",
"'(?<!/)viewtopic.php\?t=([0-9]*)&amp;highlight=([a-zA-Z0-9]*)'",
"'(?<!/)viewtopic.php\?t=([0-9]*)'",
"'(?<!/)viewtopic.php\?p=([0-9]*)'");

$urlout = array(
"viewforum\\1-\\2-\\3.php",
"mforum\\1.php",
"forum\\1.php",

"ptopic\\1.php",
"ntopic\\1.php",
"newtopic\\1.php",
"stopic\\1.php",
"utopic\\1.php",
"ftopic\\1-\\2-\\3-\\4.php",
"ftopic\\1-\\2-\\3-\\4-\\5.php",
"ftopic\\1-\\2.php",
"setopic_\\1-\\2.html",
"ftopic\\1.php",
"sutra\\1.php");

$s = preg_replace($urlin, $urlout, $s);

return $s;
}

#
#-----[ OUVRIR ]------------------------------------------
#
includes/page_tail.php

#
#-----[ TROUVER ]------------------------------------------
#
$db->sql_close();

#
#-----[ APRES, AJOUTER ]------------------------------------------
#

$contents = ob_get_contents();
ob_end_clean();
echo replace_mod_rewrite($contents);
global $dbg_starttime;


#
#-----[ TROUVER ]------------------------------------------
#
$gzip_contents = ob_get_contents();
ob_end_clean();

#
#-----[ APRES, AJOUTER ]------------------------------------------
#


echo replace_for_mod_rewrite($contents);
global $dbg_starttime;
 
WRInaute discret
ca se resume juste faire 3 modifs l'url rewriting

ou c'est beaucoup plus compliqué que cela

les codes precedent sont ils correct

existe t'il des codes plus efficaces
 
WRInaute discret
voici une deusieme methode

#
#-----[ OUVRIR ]---------------------------------------------
#
includes/sessions.php

#
#-----[ TROUVER ]---------------------------------------------
#

$SID = 'sid=' . $session_id;

#
#-----[ REMPLACER PAR ]---------------------------------------
#

if ( est_robot() && REFERENCEMENT_BOOST ){ //if ajouté pour supprimer les sessions pour les robots
$SID = '';
}else{
$SID = 'sid=' . $session_id;
}

#
#-----[ TROUVER ]---------------------------------------------
#

function append_sid($url, $non_html_amp = false)
{
global $SID;

if ( !empty($SID) && !preg_match('#sid=#', $url) )
{
$url .= ( ( strpos($url, '?') != false ) ? ( ( $non_html_amp ) ? '&' : '&' ) : '?' ) . $SID;
}

return $url;
}

Remplacer par


function append_sid($url, $non_html_amp = false) //fonction modifiée pour l'url-rewriting
{
global $SID;

if ( !empty($SID) && !preg_match('#sid=#', $url) )
{
$url .= ( ( strpos($url, '?') != false ) ? ( ( $non_html_amp ) ? '&' : '&' ) : '?' ) . $SID;
}

if ( REFERENCEMENT_BOOST )
{
$url = url_rewrite( $url );
}

return $url;
}

//Fonction qui vérifie si le visiteur est un robot comme google
function est_robot() {
global $HTTP_SERVER_VARS;
$RobotsList = array (
"antibot",
"appie",
"architext",
"bjaaland",
"digout4u",
"echo",
"fast-webcrawler",
"ferret",
"googlebot",
"gulliver",
"harvest",
"htdig",
"ia_archiver",
"jeeves",
"jennybot",
"linkwalker",
"lycos",
"mercator",
"moget",
"muscatferret",
"myweb",
"netcraft",
"nomad",
"petersnews",
"scooter",
"slurp",
"unlost_web_crawler",
"voila",
"voyager",
"webbase",
"weblayers",
"wget",
"wisenutbot",
"acme.spider",
"ahoythehomepagefinder",
"alkaline",
"arachnophilia",
"aretha",
"ariadne",
"arks",
"aspider",
"atn.txt",
"atomz",
"auresys",
"backrub",
"bigbrother",
"blackwidow",
"blindekuh",
"bloodhound",
"brightnet",
"bspider",
"cactvschemistryspider",
"cassandra",
"cgireader",
"checkbot",
"churl",
"cmc",
"collective",
"combine",
"conceptbot",
"coolbot",
"core",
"cosmos",
"cruiser",
"cusco",
"cyberspyder",
"deweb",
"dienstspider",
"digger",
"diibot",
"directhit",
"dnabot",
"download_express",
"dragonbot",
"dwcp",
"e-collector",
"ebiness",
"eit",
"elfinbot",
"emacs",
"emcspider",
"esther",
"evliyacelebi",
"nzexplorer",
"fdse",
"felix",
"fetchrover",
"fido",
"finnish",
"fireball",
"fouineur",
"francoroute",
"freecrawl",
"funnelweb",
"gama",
"gazz",
"gcreep",
"getbot",
"geturl",
"golem",
"grapnel",
"griffon",
"gromit",
"hambot",
"havindex",
"hometown",
"htmlgobble",
"hyperdecontextualizer",
"iajabot",
"ibm",
"iconoclast",
"ilse",
"imagelock",
"incywincy",
"informant",
"infoseek",
"infoseeksidewinder",
"infospider",
"inspectorwww",
"intelliagent",
"irobot",
"iron33",
"israelisearch",
"javabee",
"jbot",
"jcrawler",
"jobo",
"jobot",
"joebot",
"jubii",
"jumpstation",
"katipo",
"kdd",
"kilroy",
"ko_yappo_robot",
"labelgrabber.txt",
"larbin",
"legs",
"linkidator",
"linkscan",
"lockon",
"logo_gif",
"macworm",
"magpie",
"marvin",
"mattie",
"mediafox",
"merzscope",
"meshexplorer",
"mindcrawler",
"momspider",
"monster",
"motor",
"mwdsearch",
"netcarta",
"netmechanic",
"netscoop",
"newscan-online",
"nhse",
"northstar",
"occam",
"octopus",
"openfind",
"orb_search",
"packrat",
"pageboy",
"parasite",
"patric",
"pegasus",
"perignator",
"perlcrawler",
"phantom",
"piltdownman",
"pimptrain",
"pioneer",
"pitkow",
"pjspider",
"pka",
"plumtreewebaccessor",
"poppi",
"portalb",
"puu",
"python",
"raven",
"rbse",
"resumerobot",
"rhcs",
"roadrunner",
"robbie",
"robi",
"robofox",
"robozilla",
"roverbot",
"rules",
"safetynetrobot",
"search_au",
"searchprocess",
"senrigan",
"sgscout",
"shaggy",
"shaihulud",
"sift",
"simbot",
"site-valet",
"sitegrabber",
"sitetech",
"slcrawler",
"smartspider",
"snooper",
"solbot",
"spanner",
"speedy",
"spider_monkey",
"spiderbot",
"spiderline",
"spiderman",
"spiderview",
"spry",
"ssearcher",
"suke",
"suntek",
"sven",
"tach_bw",
"tarantula",
"tarspider",
"techbot",
"templeton",
"teoma_agent1",
"titin",
"titan",
"tkwww",
"tlspider",
"ucsd",
"udmsearch",
"urlck",
"valkyrie",
"victoria",
"visionsearch",
"vwbot",
"w3index",
"w3m2",
"wallpaper",
"wanderer",
"wapspider",
"webbandit",
"webcatcher",
"webcopy",
"webfetcher",
"webfoot",
"weblinker",
"webmirror",
"webmoose",
"webquest",
"webreader",
"webreaper",
"websnarf",
"webspider",
"webvac",
"webwalk",
"webwalker",
"webwatch",
"whatuseek",
"whowhere",
"wired-digital",
"wmir",
"wolp",
"wombat",
"worm",
"wwwc",
"wz101",
"xget",
"awbot",
"bobby",
"boris",
"bumblebee",
"cscrawler",
"daviesbot",
"ezresult",
"gigabot",
"gnodspider",
"internetseer",
"justview",
"linkbot",
"linkchecker",
"nederland.zoek",
"perman",
"pompos",
"psbot",
"redalert",
"shoutcast",
"slysearch",
"ultraseek",
"webcompass",
"yandex",
"robot",
"crawl"
);
$botID = strtolower( $HTTP_SERVER_VARS['HTTP_USER_AGENT'] );
for ($i = 0; $i < count( $RobotsList ); $i++)
{
if ( strstr( $botID, $RobotsList[$i] ) )
{
return true;
}
}
return false;
}

//fonction qui réécrit l'url des pages de lecture
function url_rewrite($url){

$inf_url = parse_url( html_entity_decode( $url ) );
$get_url = array();
parse_str( $inf_url['query'], $get_url );

//index.php
if ( substr_count( $inf_url['path'], "index" ) == 1 ){
//les catégories
if ( count( $get_url ) == 1 && isset( $get_url['c'] )){
return 'categorie-'.$get_url['c'].'.html';
}
}

//viewforum.php
if ( substr_count( $inf_url['path'], "viewforum" ) == 1 ){
//le numéro du forum seul
if ( count( $get_url ) == 1 && isset( $get_url['f'] )){
return 'forum-'.$get_url['f'].'.html';
}
//f, topicdays et start
if ( count( $get_url ) == 3 && isset( $get_url['f'] ) && isset( $get_url['topicdays'] ) && isset( $get_url['start'] ) ){
return 'forum-'.$get_url['f'].'-'.$get_url['t opicdays'].'-'.$get_url['start'].'.htm l';
}
}

//viewtopic.php
if ( substr_count( $inf_url['path'], "viewtopic" ) == 1 ){
//le numéro du sujet seul
if ( count( $get_url ) == 1 && isset( $get_url['t'] )){
return 'sujet-'.$get_url['t'].'.html';
}
//le numéro du sujet seul avec p
if ( count( $get_url ) == 1 && isset( $get_url['p'] )){
return 'vsujet-'.$get_url['p'].'.html';
}

//sujet précédent ou suivant
if ( count( $get_url ) == 2 && isset( $get_url['t'] ) && isset( $get_url['view'] ) ){
if ( $get_url['view'] == 'previous' ){
return 'prec-sujet-'.$get_url['t'].'.html';
}elseif ( $get_url['view'] == 'next' ){
return 'suiv-sujet-'.$get_url['t'].'.html';
}
}

//le numéro du sujet et start
if ( count( $get_url ) == 2 && isset( $get_url['t'] ) && isset( $get_url['start'] ) ){
return 'sujet-'.$get_url['t'].'-'.$get_url['s tart'].'.html';
}
//le numéro du sujet et postdays et postorder et start
if ( count( $get_url ) == 4 && isset( $get_url['t'] ) && isset( $get_url['start'] ) && isset( $get_url['postdays'] ) && isset( $get_url['postorder'] ) ){
return 'sujet-'.$get_url['t'].'-'.$get_url['s tart'].'-'.$get_url['postdays'].'-'.$g et_url['postorder'].'.html';
}
//le numéro du sujet et postdays et postorder et start et highlight
if ( count( $get_url ) == 5 && isset( $get_url['t'] ) && isset( $get_url['start'] ) && isset( $get_url['postdays'] ) && isset( $get_url['postorder'] ) && isset( $get_url['highlight'] ) ){
return 'sujet-'.$get_url['t'].'-'.$get_url['s tart'].'-'.$get_url['postdays'].'-'.$g et_url['postorder'].'('.urlencode( $get_url['highlight']).').html';
}

}

//profile.php
if ( substr_count( $inf_url['path'], "profile" ) == 1 ){
//mode=viewprofile et num du profil
if ( count( $get_url ) == 2 && isset( $get_url['mode'] ) && $get_url['mode'] == "viewprofile" && isset( $get_url['u'] ) ){
return 'profil-'.$get_url['u'].'.html';
}
}

return $url;
}








Pour activer ou desactiver url rewriting

#
#-----[ OUVRIR ]---------------------------------------------
#

includes/constants.php

#
#-----[ TROUVER ]---------------------------------------------
#

// Session parameters
define('SESSION_METHOD_COOKIE', 100);
define('SESSION_METHOD_GET', 101);

#
#-----[ APRES, AJOUTER ]------------------------------------------
#


//amélioration du référencement : suppression des sessid pour les robots et url-rewriting
define('REFERENCEMENT_BOOST', true);





Si vous définissez la constante précédente à faux, remplacez le code précédent par

//amélioration du référencement : suppression des sessid pour les robots et url-rewriting
define('REFERENCEMENT_BOOST',false);







Uploadez un fichier .htaccess dans la racine de votre forum, avec ce code.

Rew riteEngine On
RewriteRule ^index\-([0-9]*)\.html$ index.php?c=$1 [L]
RewriteRule ^forum\-([0-9]*)\.html$ viewforum.php?f=$1 [L]
RewriteRule ^forum\-([0-9]*)\-([0-9 3;*)\-([0-9]*)\.html$ viewforum.php?f=$1&topicdays=$2&start=$3 [L]
RewriteRule ^sujet\-([0-9]*)\.html$ viewtopic.php?t=$1 [L]
RewriteRule ^sujet\-([0-9]*)\-([0-9 3;*)\.html$ viewtopic.php?t=$1&start=$2 [L]
RewriteRule ^sujet\-([0-9]*)\(([^& #40;)]*)\)\.html$ viewtopic.php?t=$1&highlight=$2 [L]
RewriteRule ^sujet\-([0-9]*)\-([0-9 3;*)\-([0-9]*)\-([a-zA -Z]*)\.html$ viewtopic.php?t=$1&start=$2&postdays=$3&am p;postorder=$4 [L]
RewriteRule ^sujet\-([0-9]*)\-([0-9 3;*)\-([0-9]*)\-([a-zA -Z]*)\(([^()]*) ;\)\.html$ viewtopic.php?t=$1&start=$2&postdays=$3&am p;postorder=$4&highlight=$5 [L]
RewriteRule ^vsujet\-([0-9]*)\.html$ viewtopic.php?p=$1 [L]
RewriteRule ^prec\-sujet\-([0-9]*)\.html$ viewtopic.php?t=$1&view=previous [L]
RewriteRule ^suiv\-sujet\-([0-9]*)\.html$ viewtopic.php?t=$1&view=next [L]
RewriteRule ^profil\-([0-9]*)\.html$ profile.php?mode=viewprofile&u=$1 [L]






Toujours dans la racine un fichier robots.txt

Dis allow: /répertoire de votre forum/sutra*.html$
Disallow: /répertoire de votre forum/ptopic*.html$
Disallow: /répertoire de votre forum/ntopic*.html$
Disallow: /répertoire de votre forum/ftopic*asc*.html$
 
Discussions similaires
Haut