reescribir www. a no www sin especificar el dominio?

I was using this code to remove www from my domain:

# remove www
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

My problem is that I usually use subdomains and it doesn't work for them. (www.sub.example.com).

How do I rewrite to remove www whatever the domain is and even if it has subdomains?

preguntado el 01 de julio de 12 a las 01:07

What is your question? Just Now - I upvoted it. -

Sorry I submitted it accidentally just edited the question -

2 Respuestas

Prueba esto:

#********** Remove www from address **********
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC]

This is a bit more correct than the other solution.

Edit: I removed [L] as it isn't applicable here.
Though in most cases [NC] non-case sensitive is recommended.

Respondido el 29 de Septiembre de 12 a las 08:09

You could probably use capture groups and combine with rewrites... (Completely untested guess)

# remove www
RewriteCond %{HTTP_HOST} ^www.(.*) [NC]
RewriteRule ^(.*)$ http://$1 [R=301,L]

Respondido 01 Jul 12, 02:07

Looks like someone else beat me to it with that answer. Not really gonna steal their thunder, if that's the right answer. - RonLugge

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.