views:

65

answers:

2

In a virtual host in apache I would like to redirect all requests to <anything>.mydomain.<anything> to just mydomain.com.

However, the below rewrite rule is ignored for some reason. Why?

RewriteCond %{REMOTE_HOST}  ^.*mydomain.*
RewriteRule ^(.*)$ http://mydomain.com [R=301,L]
+1  A: 

You could use this rule to redirect every request with a host other than example.com to example.com:

RewriteCond %{HTTP_HOST}  !^example\.com$
RewriteRule ^ http://example.com%{REQUEST_URI} [R=301,L]
Gumbo
+1  A: 

%{REMOTE_HOST} refers to the name of the computer that's accessing your website - it's "remote" from the server's perspective. As Gumbo pointed out, you should be using %{HTTP_HOST}.

David Zaslavsky