Htaccess genérico redirige www a no www

Resuelto deepwell asked hace 15 años • 25 respuestas

Me gustaría redirigir www.example.coma example.com. El siguiente código htaccess hace que esto suceda:

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

Pero, ¿hay alguna manera de hacer esto de forma genérica sin codificar el nombre de dominio?

deepwell avatar Oct 25 '08 01:10 deepwell
Aceptado
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

Igual que el de Michael excepto que este funciona :P

 avatar Aug 13 '2009 06:08

Pero si necesitamos hacer esto para http y https por separado:

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

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Andron avatar Mar 19 '2010 08:03 Andron