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:
i want to to be

I need it to work with all subdomains…

Thanks in advance.


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).



Thanks for your reply.

I didn’t create any subdomains. However, i want it so if anyone tried to open any it will redirect him to the correct page which is

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


If someone linked to, 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.



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