Page 1 sur 1

Script de redirection sans tenir compte...........

Posté : 21 mars 2007, 21:07
par Pingwin
Bonjour!
Je voudrais faire un script de redirection qui ne tient pas compte de PHPSESSID=.
Je vous explique: Voulant remplacer mon ancien site http://www.linux-aide.org par http://wiki.linux-aide.org, sans déstabiliser les visiteurs/robots, j'ai fait un petit script PHP qui à chaque page de l'ancien site, associait la redirection vers la nouvelle page:
<?php
header("HTTP/1.1 301 Moved Permanently");
if($_SERVER["REQUEST_URI"] === "/articles.php?lng=fr&pg=48")
header("Location: http://wiki.linux-aide.org/index.php?n= ... CeQueLinux");
if($_SERVER["REQUEST_URI"] === "/articles.php?lng=fr&pg=574")
header("Location: http://wiki.linux-aide.org/index.php?n= ... onHistoire");
if($_SERVER["REQUEST_URI"] === "/articles.php?lng=fr&pg=549")
header("Location: http://wiki.linux-aide.org/index.php?n= ... LaMascotte");
Seul problème, lorsqu'un PHPSESSID est associé à la page, comme par exemple sur des liens référencés dans google ou dans des favoris de visiteurs, le script ne marche plus.
Comment faut il donc faire pour ne pas tenir compte de PHPSESSID?
J'ai essayé le script suivant mais sans succès.......
<?php
header("HTTP/1.1 301 Moved Permanently");
if(strpos($_SERVER["REQUEST_URI"], "articles.php?lng=fr&pg=48") <> FALSE)
header("Location: http://wiki.linux-aide.org/index.php?n= ... CeQueLinux");
if(strpos($_SERVER["REQUEST_URI"], "/articles.php?lng=fr&pg=574") != false)
header("Location: http://wiki.linux-aide.org/index.php?n= ... onHistoire");
if(strpos($_SERVER["REQUEST_URI"], "/articles.php?lng=fr&pg=549") !=FALSE)
header("Location: http://wiki.linux-aide.org/index.php?n= ... LaMascotte");
Avez vous une idée pour résoudre mon problème?
Merci d'avance
Bonne soirée!

Posté : 22 mars 2007, 22:38
par Pingwin
Personne n'a d'idée???

Posté : 23 mars 2007, 08:08
par raptor
L'astuce serait de créer une variable style
$provenance = $_SERVER["REQUEST_URI"];

Sur cette variable, tu lance un ereg_replace visant a remplacer &PHPSESSID=56465464545555 par rien, et ensuite tu fais tes "if" non pas sur $_SERVER["REQUEST_URI"] mais sur $provenance.

Posté : 23 mars 2007, 12:40
par Bluebird75
Salut!
Sauf que le problème vient du fait que le PHPSESSID est variable, et que je ne peux pas le désactiver avec guppy, sinon "Internal Server error"... Il faudrait donc une fonction qui supprime &PHPSESSID= et tout ce qui le suit, ce que je n'ai pas trouvé dans la fiche sur ereg...

Posté : 23 mars 2007, 13:14
par AB
Bonjour,

Pour enlever le PHPSESSID en fin d'url :
$provenance = $_SERVER["REQUEST_URI"]; 

$url = preg_replace('/&PHPSESSID=.+/', '', $provenance);

Posté : 23 mars 2007, 19:12
par Pingwin
Ca fonctionne!!! Merci beaucoup!
Voici le code (au cas au quelqu'un d'autre aurait le même pb)
<?php
$provenance = $_SERVER["REQUEST_URI"];
if(strpos($_SERVER["REQUEST_URI"], "&PHPSESSID=") <> FALSE)
$url = preg_replace('/&PHPSESSID=.+/', '', $provenance);
else $url = $_SERVER["REQUEST_URI"];

header("HTTP/1.1 301 Moved Permanently");
if($url === "/articles.php?lng=fr&pg=48")
header("Location: http://wiki.linux-aide.org/index.php?n= ... CeQueLinux");
if($url === "/articles.php?lng=fr&pg=574")
header("Location: http://wiki.linux-aide.org/index.php?n= ... onHistoire");
if($url === "/articles.php?lng=fr&pg=549")
header("Location: http://wiki.linux-aide.org/index.php?n= ... LaMascotte");
...................
................
.................
Merci beaucoup!