All subdomains redirect to one subdomain

Need to redirect the all sub-domains, except en.domain.com
to en.domain.com

Like
www.domain.com/en/ -> en.domain.com
www.domain.com/en/test -> en.domain.com/test
www.domain.com/en/dir/index.htm -> en.domain.com/dir/index.htm

domain.com/en/ -> en.domain.com
domain.com/en/test -> en.domain.com/test
domain.com/en/dir/index.htm -> en.domain.com/dir/index.htm

What is wrong with the following code?

RewriteEngine on
RewriteCond %{HTTP_HOST} !^en.* [NC]
RewriteRule ^/en/(.*) http://en.domain.net/$1 [L,R]

pedro,

This code will redirect www’d domains to en.domain.net, too!

Worse:

  1. You should escape the dot in the RewriteCond and then NOT include the * metacharacter as that causes this to match encyclopedia.whatever. That’s NOT your intention (at least I hope it’s not).

  2. In an .htaccess file, ^/whatever will only be matched by an Apache 1.x server. If you’re using Apache 2.x, drop the /; if you’re not sure, use ^/?.

  3. R’s default is 302 (temporary) so, if you want SE’s to update, change that to R=301.

Where is the document for the en subdomain? If it’s the en subdirectory, that means that you’re set but, if not, then you’ve got some more work to do.

Regards,

DK