EDIT:

How can you redirect all non-active subdomains to 'www'?

Here I try to redirect all subdomains not listed to 'www'.. I can't make it work properly because %1 and %2 doesn't return anything.. Here I'm trying to redirect to google.com just to check the returned %2 value.., but it doesn't return anything and the redirect url is http://www.google.com/

RewriteCond %{HTTP_HOST}        !^(admin|demo|www)\.([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$          http://www.google.com/%2 [L,R=301]

this is what I really want to do

RewriteCond %{HTTP_HOST}        !^(admin|demo|www)\.([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$          http://www.%2/$1 [L,R=301]
link|improve this question

69% accept rate
give actual examples of start end points and I can write one – Mike May 25 '11 at 15:05
like this? .... – clarkk May 26 '11 at 17:27
could anybody help? – clarkk May 29 '11 at 18:19
feedback

2 Answers

RewriteCond %{HTTP_HOST} !^(www|admin|files|mysql\.)domain\.com$ [NC]
RewriteRule ^ http://www.domain.com%{REQUEST_URI} [NE,L,R=301]

Untested but it should work..

link|improve this answer
1  
shouldn't the \. in the rewritecond be outside the parens? – DTest May 25 '11 at 14:44
what does the NE flag mean? – clarkk May 25 '11 at 14:50
I have edited my q – clarkk May 25 '11 at 14:54
NE is no escape do you don't double encode the url – Mike May 25 '11 at 15:04
feedback

Presuming DNS entries already exist, you could use something I do on a couple domains:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$
    RewriteRule ^/(.*)$ http://mydomain.com/%1/$1 [L,R]

This takes requests in the form of sub.domain.com and pushes it to domain.com/sub.

You could remove the %1 and get the following which would not use the subdomain-to-path method I'm employing thusly:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$
    RewriteRule ^/(.*)$ http://mydomain.com/$1 [L,R]
link|improve this answer
thats not what im looking for – clarkk May 25 '11 at 16:34
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.