Replace ALL subdomain with "www" and pass the parameters

Hello everyone,

I have pretty new to mod_rewrite and regular expressions…

I need to replace all subdomains with “www” and pass the same parameters. example:
xxx.mydomain.com/subdir/?var=123
i want to to be
www.mydomain.com/subdir/?var=123

I need it to work with all subdomains…

Thanks in advance.
Adel

LA,

Hmmm, kill all subdomains? Why have them at all then?

Oh, well, test for existance of subdomain which is NOT www then redirect to the www’d version with %{REQUEST_URI} and let the %{QUERY_STRING} be passed automatically (as it will be unless you create a new query string).

Regards,

DK

Thanks for your reply.

I didn’t create any subdomains. However, i want it so if anyone tried to open any xxx.mydomain.com/subdir/?var=123 it will redirect him to the correct page which is www.mydomain.com/subdir/?var=123

As i told you, i am pretty new to this…so i will appreciate if someone could tell me how to do it using .htaccess

LA,

If someone linked to xxx.mydomain.com, it would FAIL if xxx was not a registered subdomain. Subdomains are treated the same as a domain so, if it’s not registered with your DNS, you won’t ever see the request.

… and .htaccess has nothing to do with DNS, only Apache.

Regards,

DK

Ahaa, thanks for your reply…
So i have to register possible subdomains with DNS first… i might then do redirection using php…