How can this be done??? [ a hard one? ]

Topics: Developer Forum, User Forum
Aug 17, 2008 at 8:36 PM
Look at the example below:

http://domain.com >> http://www.domain.com
http://www.domain.com >> leave as is
http://test.domain.com >> http://www.domain.com/?q=test


the first rule is if there is no prefix subdomain, add "www."
the second rule is if subdomain exists, move it to the parameter.
and third, and the tricky - is if the subdomain is "www" don't touch the url, dont rewrite it!

Please advice :-) Thanks!
Aug 18, 2008 at 10:58 AM
hi

so long as your dns is setup to accept [anything].domain.com then have a look at this, the regex should be fairly similar.

http://www.seoconsultants.com/windows/isapi/subdomains/
Coordinator
Aug 21, 2008 at 12:54 PM

this might be close to what you want:

  # do nothing with any URLs that uses www prefix as the hostname 
  RewriteCond %{SERVER_NAME} ^(www\.)domain.com$
  RewriteRule ^/(.*)$  -   [L]

  # for URLs that use the bare domain, redirect to the www host
  RewriteCond %{SERVER_NAME} ^domain.com$
  RewriteRule ^/(.*)$    http://www.domain.com/$1   [R]

  # for other URLs, redirect and rewrite.  Handle the case with no query string:
  RewriteCond %{SERVER_NAME} ^(.+\.)domain.com$
  RewriteRule ^/([^?]*)$      http://www.domain.com/$1?q=%1  [R]

  # handle the case with a query string
  RewriteCond %{SERVER_NAME} ^(.+\.)domain.com$
  RewriteRule ^/(.*)$      http://www.domain.com/$1&q=%1  [R]