Dynamic sub domains

Topics: Developer Forum, Project Management Forum, User Forum
Jan 26, 2008 at 6:50 PM
Is there a solution in IIRF for creating dynamic sub domains like this?

xyz.domain.com = www.domain.com/xyz/

A similar solution described for ISAPI rewrite doesn't work for IIRF. Creating Dynamic Subdomains in Windows/IIS using ISAPI_Rewrite. http://www.seoconsultants.com/windows/isapi/subdomains/

I have been searching for this over a week now, if I know IIRF isn't the solution I would at least stop trying for it.

Jan 27, 2008 at 1:32 PM
yes it is, you are in the right place
Jan 27, 2008 at 3:35 PM
Could you please give the solution?

TMhe code given in http://www.seoconsultants.com/windows/isapi/subdomains/ works only for ISAPi Reqrite not for IIRF...
Jan 30, 2008 at 2:16 PM
OK ArijitU

I think I found your solution:

assuming that you have changed your DNS configuration as shown here

so that *.domain.com -> goes to your ip address

you can do this:

http://AAAA.domain.com -> /url.asp?subdomain=AAAA
RewriteCond %{HTTP_HOST} (.*)\.domain.com I
RewriteRule ^(.*)$ /url.asp?subdomain=%1 U,L

http://AAAA.domain.com -> /AAAA/default.asp
RewriteCond %{HTTP_HOST} (.*)\.domain.com I
RewriteRule ^(.*)$ /%1/ U,L

Does it work?

Jan 30, 2008 at 6:06 PM
That should work!
Feb 10, 2008 at 10:24 AM
This won't work perhaps because when you are dpoing a replacement of the 'subdomain part' from url you you are directing the user to a path under the same subdomain -

see here - RewriteRule ^(.*)$ /url.asp?subdomain=%1 U,L ....................here /url.asp is a url under the subdomain AAAA.

We need to redirect a user who types AAAA.domain.com to www.domain.com/url.asp?subdomain=%1 or domain.com/url.asp?subdomain=%1

so this might work -
RewriteRule ^(.*)$ www.domain.com/url.asp?subdomain=%1 U,L ........but then this is not rewrting its redirection, and here some mess up works.

Can't resolve.
Feb 10, 2008 at 6:18 PM

Well ! If i did understand right you want to redirect the subdomain AAAA to
and not to

Ok, that is fine...


it tells you to change your DNS configuration of your domain so that EVERY SUBDOMAIN THAT DOES NOT EXIST
will be redirected automatically to your original domain

*.domain.com -> your IP (the IP of www.domain.com)

On your server YOU DONT HAVE TO CREATE the subdomain AAAA.domain.com -> it is VIRTUAL

if you place *.domain.com it will redirect every subdomain that does not exist to www.domain.com or domain.com (JUST AS YOU WANT)

http://AAAA.domain.com -> /url.asp?subdomain=AAAA
RewriteCond %{HTTP_HOST} (.*)\.domain.com I
RewriteRule ^(.*)$ /url.asp?subdomain=%1 U,L

-> IMPORTANT -> the page URL.ASP is not on AAAA.domain.com (that actually does not exist) but is on www.domain.com

hope i did help you!!! It was hard at the beginnig even for me :-)
Feb 11, 2008 at 2:37 PM
Hi Ginnarino,

Thank you for your helps. I understand what you are saying and what they have said here - http://www.seoconsultants.com/windows/isapi/subdomains/. But my problem is a bit more complicated, I am elaborating the problem:

I am running multiple domains on single IP and so while I have configured DNS, I cannot use wildcard domains in real sense and I am trying to workaround and tweak-a-bit to achive my result.

This is what I have done:

1. Configured wildcard MS DNS - *.domain.com -> myIP, till this point I have followed the rules.

2. Apart from default website in IIS, I have multiple domains using the same IP as www.domain.com, www.domain1.com, www.domain2.com

3. Now since IIS6 does not support wild-card host-headers, all non-defined host header web requests goes to 'default website'. So a request for AAAA.domain.com also goes to 'default website'

4. For this I have applied the ISAPI filter on the default website.

5. Now if I use this -
RewriteCond %{HTTP_HOST} (.*)\.domain.com I
RewriteRule ^(.*)$ /url.asp?subdomain=%1 U,L

IIS will try to search for a page www.defaultwebsite/url.asp?subdomain=%1, which it cannot find as there is no such page.
If I use -
RewriteCond %{HTTP_HOST} (.*)\.cyp.in I
RewriteRule ^(.*)$ http://www.domain.com/srchDetails.asp?clientid=%1 R

The redirection and wildcard sub-domain thing works but the URL shows up.
This is better but not complete solution to the my goal.
The rewriting does not work without visible redirection.
Nov 3, 2009 at 2:23 PM

Hi all,

I am trying to configure dynamic sub domains but receive an error page 

Bad Request (Invalid Hostname)

what could be a problem.

1) I configured *.domain.com -> to my ip address

2) And modefied http ISAPI_Rewrite to this

RewriteCond %{HTTP:Host} ^(.*)\.domain\.com$
RewriteRule (.*) $1 [I]

So I need all subdomains process by one WebSite.

Nov 3, 2009 at 2:37 PM


#RewriteCond %{HTTP_HOST} (.*)\.behere.eu [I]
#RewriteRule (.*) /url.asp?user=%1 [U,L]

Try using something like this:

RewriteCond %{HTTP_HOST} (.*)\.yourdomain.com [I]
RewriteRule (.*) /url.asp?subdomain=%1 [U,L]

I am not a big expert but from what i remember notice that when you use VARIABLE you should use %1 and not $1 in you code.
Please let me know if i was helpfull 



Nov 3, 2009 at 2:44 PM

No. It did not help.

The idea is not to process all requests by some page like url.asp, but to map all the requests to one web site.

so I want to process aaa.domain.com, bbb.domain.com, some-other.domain.com by domain.com web site.

May be the problem is that I have multiple web sites on my server?

so current IIS has 2 web sites:

* domain.com

* othersite.com

and I want *.domain.com be processed by domain.com.

Nov 3, 2009 at 3:08 PM

OK, i did something like you are trying to do.

to manage all the subdomains as *.domain.com to be redirect to a single domain i used the DEFAULT SITE IN IIS as your domain.com

To do you so you dont need to use IIRF, just disable in iis your domain.com and every request to www.domain.com, blabla.domain.com, aaa.domain.com, etc. will be redirect to the iis default website.

Place your code in the default site, or set your domain.com as default site.



Nov 3, 2009 at 5:53 PM

Did not understand your solution.

What do you mean disable in IIS domain.com?

What do you mean set domain.com as default? How can I do that? Is it an IIS option or IIRF?

I need not REDIRECT, but REWRITE. I mean that a request of asdfasdf.domain.com must be processes as domain.com. It should process *.domain.com requests.

PS: I use WS 2003 and IIS6.0, so I have several different sites.

Nov 4, 2009 at 10:03 AM
neyman wrote:

I need not REDIRECT, but REWRITE. I mean that a request of asdfasdf.domain.com must be processes as domain.com. It should process *.domain.com requests.

PS: I use WS 2003 and IIS6.0, so I have several different sites.

Normally you can do what you want using hostname aliases - DNS names.  This is not an IIS or IIRF configuration.  It is DNS.

Or maybe I have not understood what you want.  What do you mean, exactly, by "a request of asdfasdf.domain.com must be processes as domain.com." ??

Is the website for asdfasdf.domain.com  hosted on the same physical server as the website for domain.com ?    Are you saying you want the browser address bar to update to domain.com?  or you want it to remain the same (asdfasdf.domain.com) ?    I guess you'll have to elaborate on what you want.  The problem is, there are many many possibilities, and saying "a request must be processed as domain.com" doesn't quite clarify what you want.



Nov 4, 2009 at 10:45 AM
Edited Nov 4, 2009 at 10:47 AM

Ok, I'll try to clarify.

So I configured DNS:

domain.com -> ServerIP

*.domain.com -> ServerIP

Now when ping domain.com or aaa.domain.com or [whatever].domain.com I see the same IP address.

In IIS6 I create a new web site. Host header value set to domain.com. Local path (Home Directory tab in web site properties in IIS) I type D:\WebSites\domain.com

In folder D:\WebSites\domain.com I create a file default.htm with text "Hello world".

Now when I type in browser address http://domain.com/default.htm I see "Hello world".

I want to see the same when I type in browser address http://aaa.domain.com/default.htm or http://[whatever].domain.com/default.htm.

But I see

Bad Request (Invalid Hostname)

Nov 4, 2009 at 5:10 PM

yes, ok, I see.

I don't know too much about that problem, but it seems to be related to IIS, not IIRF, and fortunately, it seems to be a common error. and a bunch of people have shared how they fixed it.

Good luck.

Nov 5, 2009 at 9:30 AM

Is this domain on its own IP address? This is AFAIK the only way to do this.

If you set up the wildcard in the DNS, like you've done, and set the site up on your server to have no headers, then it will pick up all of the DNS forwards.

If this IP is shared among a few different sites, then this won't work as well. You could still set this site up with no headers, but if one of the other sites uses a non-recognised header, then it will show this domain - not ideal.

Make sense?


Nov 5, 2009 at 9:39 AM

Appreciate your answer.

I figured this yesterday :)

If host header value is set to empty then everything works as I expected.

Appreciate your answer.
I figured this yesterday :)
If host header value is set to empty then everything works as I expected.