Foros del Web » Programando para Internet » PHP »

Redirigir www a no-www con PHP ?

Estas en el tema de Redirigir www a no-www con PHP ? en el foro de PHP en Foros del Web. Hola, mi pregunta es como puedo redirigir el tráfico del subdominio "www." hacia el dominio original sin el "www" delante. No me sirve la solucion ...
  #1 (permalink)  
Antiguo 30/09/2007, 05:01
.:Chimera:.
Invitado
 
Mensajes: n/a
Puntos:
Redirigir www a no-www con PHP ?

Hola, mi pregunta es como puedo redirigir el tráfico del subdominio "www." hacia el dominio original sin el "www" delante.


No me sirve la solucion del htaccesss así que necesitaré un script php que me lo pueda hacer, lo he intentado con las variables $_SERVER[] y el header('Location') pero siempre salen errores...

Un saludo.
  #2 (permalink)  
Antiguo 30/09/2007, 11:46
Avatar de ESNOLA  
Fecha de Ingreso: octubre-2006
Mensajes: 188
Antigüedad: 17 años, 6 meses
Puntos: 20
Re: Redirigir www a no-www con PHP ?

Crea una redireccion en el index.html
es decir que en el index.html te figure esto:

<html>
<head>
<meta http-equiv="refresh" content="0;URL=http://todo-mods.com/">
<title></title>
</head>
<body>

</body>
</html>
  #3 (permalink)  
Antiguo 03/10/2007, 13:48
.:Chimera:.
Invitado
 
Mensajes: n/a
Puntos:
Re: Redirigir www a no-www con PHP ?

no me sirve, necesito redireccionar todas las páginas, no solo el index.
  #4 (permalink)  
Antiguo 03/10/2007, 13:56
Avatar de el cirujano  
Fecha de Ingreso: mayo-2003
Ubicación: Frente al PC
Mensajes: 609
Antigüedad: 20 años, 11 meses
Puntos: 3
Re: Redirigir www a no-www con PHP ?

Chimera porque no posteas tu codigo asi aqui le hechamos un ojo?:O
__________________
CSS2 + AJAX + PHP + MySQL, una mezcla sin competencia!!!!!!
  #5 (permalink)  
Antiguo 03/10/2007, 14:17
.:Chimera:.
Invitado
 
Mensajes: n/a
Puntos:
Re: Redirigir www a no-www con PHP ?

Ok, lo primero que he provado es esto:

Código PHP:
if (strstr$_SERVER['HTTP_HOST'], 'www.' ) ){

header('Location: http://' substr($_SERVER['HTTP_HOST'], 4) . $_SERVER['REQUEST_URI']);
exit();

Pero aunque no lo creas no hace nada, la web sigue funcionando con el www.

Ahí es donde me he quedado, xDDD
  #6 (permalink)  
Antiguo 03/10/2007, 14:27
Avatar de Seppo  
Fecha de Ingreso: marzo-2005
Ubicación: Buenos Aires, Argentina
Mensajes: 1.284
Antigüedad: 19 años, 1 mes
Puntos: 17
Re: Redirigir www a no-www con PHP ?

Haciendo

Código PHP:
$_SERVER['HTTP_HOST'] = 'www.mipagina.com';
if (
strstr($_SERVER['HTTP_HOST'], 'www.' )) {
    
header('Location: http://' substr($_SERVER['HTTP_HOST'], 4) . $_SERVER['REQUEST_URI']);
    exit();

Obtengo

Código:
Status: 302
X-Powered-By: PHP/5.2.0
Location: http://mipagina.com
Content-type: text/html
Así que el problema parece otro... probá usar SERVER_NAME en vez de HTTP_HOST a ver si funciona... pero es una posibilidad
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:04.