Version complète: sur le forum Webmaster Hub : URL Rewriting dans le titre
Webmaster Hub > Création et exploitation de Sites Internet > Les langages du Net > PHP
Poppy
Bonjour,

Suite à ce topic : http://www.webmaster-hub.com/index.php?showtopic=7667

J'ai voulu faire de même, or il n'y a juste qu'une redirection, l'url de ma page rechange après sad.gif

Pouvez-vous jeter un coup d'oeil:
http://www.cool-attitude.net/index.php?cat=article&id=12681

http://www.cool-attitude.net/article-referencement.html


.htaccess
CODE
RewriteRule   ^article-([a-z]+)?.html$   pages/fonction.php?nom=$1 [L]


fonction.php
CODE
<?

function code_url($string)
{
$string = strtolower($string);
$string = str_replace("( |')", "_", $string);
$accent = array('â','à','é','è','ê','î','ô','û','ç');
$sans_accent = array('a','a','e','e','e','i','o','u','c');
$string = str_replace($accent, $sans_accent, $string);
$string = eregi_replace("[^a-z0-9]","_",$string);
$string = eregi_replace("(^(_)*|(_)*$)","",$string);
return $string;
}

// connexion

$db_server = "****";  // The name of your server
$db_username = "****"; // The MySQL username
$db_password = "***"; // The MySQL password
$db_name = "****";  // The name of the database where your forums are installed

mysql_connect("$db_server","$db_username","$db_password");
mysql_select_db("$db_name");


$DB = mysql_query("SELECT title, tid FROM ibf_topics ORDER BY tid ASC");
while ($i=mysql_fetch_array($DB))
    {
    if (code_url($i["title"])==$_GET["nom"])
    {
    header("HTTP/1.1 301 Moved Permanently");
    $id=$i["tid"];
    header("Location:http://www.cool-attitude.net/index.php?cat=article&id=$id");
    header("Connection: close");
    }
    }
?>



Merci d'avance,


Sébastien
Phobos
Salut,
Tu fais toi même la redirection là :
CODE
header("HTTP/1.1 301 Moved Permanently");
$id=$i["tid"];
header("Location:http://www.cool-attitude.net/index.php?cat=article&id=$id");
header("Connection: close");

remplace peut être cela par:
CODE
$id=$i["tid"];
include("index.php?cat=article&id=$id");
Dan
Bonjour Poppy,

A mon sens l'erreur se trouve à deux niveaux.

Le premier niveau est l'utilisation d'une entête 301 vers l'URL non réécrite. Le but n'est pas que les moteurs indexent cette URL non réécrite mais la forme "user friendly", non ?
Dans ce cas, l'entête 301 est de trop.

Le deuxième niveau concerne l'utilisation de la fonction header().
Celle-ci fera toujours changer l'URL apparente de ta page. Elle n'offre pas du tout les mêmes fonctionnalités qu'une redirection Apache faite par mod_rewrite vu qu'elle est utilisée pour les redirections et non pour les réécritures d'URLs.

Dan
Poppy
Merci Phobos, ça marche à présent IMSTP3.gif

CODE
$id=$i["tid"];
include("index.php?cat=article&id=$id");


Il n'a pas aimé le lien relatif, alors j'ai mis le chemin entier smile.gif

Je vous remercie tous les deux pour votre aide précieuse, je suis trop content ^_^
Ceci est une version "bas débit" de notre forum. Pour voir la version complète avec plus d'information, la mise en page et les images, veuillez cliquer ici.