Pergunta

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]
Foi útil?

Solução

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 em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top