rewrite subdirectories to subdomains

Topics: Developer Forum, Project Management Forum, User Forum
Oct 7, 2009 at 5:35 PM


We have an application hat has a lot of subdomains like this:



And we want to rewrite all incoming requests like this:



We have tried to configure the IsapiRewrite4.ini like this, but it doesn't work for us:

RewriteCond %HTTP_HOST ^(?!www\.myhost\.com).*$    [I]
RewriteRule ^/([^/]+)/(.*) http://$$2    [I]

Rewrite Log shows something like this in its last lines:

Wed Oct 07 18:18:43 -  1980 - DoRewrites: Rewrite Url to: ''

But our application gets this URL:


Can anyone help us to get the correct answer to this problem? We don't want a RedirectRule due to external requirements.

Thank you in advance

Oct 7, 2009 at 9:58 PM

ok, what do you mean by "we want to rewrite all incoming requests" ?   The example you gave changes the hostname, as well as the url path. 

It is not possible to change the the hostname in a rewrite.  A Rewrite by definition works on the URL path only - that is everything after the hostname and port.   

It's possible to change the HTTP Header (HOST) but .. that requires a RewriteHeader, and it doesn't seem like that's what you want.

If you want to forward the request to another host - that's a redirect. (or a proxy).  Rewrite won't do that.

Maybe you could explain in more detail what you hope to accomplish by "rewriting"



Oct 7, 2009 at 10:58 PM

The problem comes with google adwords.

We have to make a link to in an advertisement, but we can't put in the "host" field of the advertisement because its length is longer than the 35 chars that Google permits (I'm talking about the real domain name, this example is shorter). So, we thought about putting in the "host" field, but then Google didn't allow us to put a link to because they were different hosts. Finally, they also don't like redirections and don't allow campaigns with redirects, that's why we don't want to use redirection.

So we thought about doing something like rewriting URL to get the solution of this problem.

If you think you can help us in another way, we would be pleased.

Oct 8, 2009 at 7:52 PM

nope, I'm afraid I don't get it at all. 

What do you hope to accomplish by rewriting or redirecting?  What is different if you get this to work the way you imagine?

you say you have to link to .   Why can you not link to   Why must you link to a different domain?  IF the problem is one of hostname lengths, why not just use shorter hostnames?  Why do you have different hostnames anyway?  Why can you not just link to

I don't get the problem you are trying to solve, so i don't know how to help you.