Bonjour,

je suis confrontée à un problème un peu particulier. Je dois faire un bout de code pour faire une redirection mais non pas par le .htacess cela aurait été "trop simple" (j'y ai pas accès), mais en php.

Voilà la problématique:

une redirection existe déjà.

Elle redirige http://www.domaine.fr ou bien http://domaine.fr vers http://www.domaine.fr/catalog.php.

Ce que je voudrais faire:

C'est garder cette redirection vers catalog.php mais en plus faire en sorte que toutes les adresses sans le www soient redirigées vers le www, et ce sur l'index ou non.

Soit http://domaine.fr vers http://www.domaine.fr/catalog et par exemple également http://domaine.fr/other ver http://www.domaine.fr/other

Le code existant est celui ci:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
header ("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.domaine.fr/catalog.php".$affiliationCheck);
Il fait effectivement une redirection de http://domaine.fr vers http://www.domaine.fr/catalog.php mais les autres adresses sans les www ne sont pas réécrites.

Dans ce bout de code que j'ai rééécrit, quelque chose ne semble pas être correct:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
header ("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.domaine.fr/catalog.php".$affiliationCheck);
$host = strtolower($_SERVER["HTTP_HOST"]); 
if ($host != "www.domaine.fr") 
{ or $host == "domaine.fr" $uri = $_SERVER["REQUEST_URI"]; 
header("HTTP/1.1 301 Moved Permanently"); 
header("Location: http://www.domaine.fr$uri"); exit(); 
}
Est ce que ca c'est correct ?

Sinon quelqu'un peut il m'aider à trouver une solution ?

Merci d'avance,
Nathalie