Pregunta

I've used the following to redirect domain.tld and *.domain.tld to www.domain.tld (except subdomain dev.domain.tld). But this doesn't seem to work for domains containing a dash like dom-ain.tld. Why?

RewriteCond %{HTTP_HOST} !^[www|dev]\.* [NC]
RewriteRule ^(.*) http://www\.%{HTTP_HOST}/$1 [R=301]
¿Fue útil?

Solución

Your regex is actually incorrect.

Replace your rule with this:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www|dev)\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top