1

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]
3
  • give actual examples of start end points and I can write one
    – Mike
    May 25, 2011 at 15:05
  • like this? ....
    – clarkk
    May 26, 2011 at 17:27
  • could anybody help?
    – clarkk
    May 29, 2011 at 18:19

2 Answers 2

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

4
  • 1
    shouldn't the \. in the rewritecond be outside the parens? May 25, 2011 at 14:44
  • what does the NE flag mean?
    – clarkk
    May 25, 2011 at 14:50
  • I have edited my q
    – clarkk
    May 25, 2011 at 14:54
  • NE is no escape do you don't double encode the url
    – Mike
    May 25, 2011 at 15:04
-1

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]
1
  • thats not what im looking for
    – clarkk
    May 25, 2011 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .