rewrite subdirectories to subdomains

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

Hi!!

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

www.myhost.com

subdomain1.myhost.com

subdomain2.myhost.com

...

 

And we want to rewrite all incoming requests like this:

www.myhost.com/subdomain1/otherStuff

To:

subdomain1.myhost.com/otherStuff

 

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://$1.myhost.com/$2    [I]

Rewrite Log shows something like this in its last lines:

Wed Oct 07 18:18:43 -  1980 - DoRewrites: Rewrite Url to: 'http://subdomain1.myhost.com/otherStuff'

But our application gets this URL:

http://www.myhost.com/otherStuff

 

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

Coordinator
Oct 7, 2009 at 8: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"

www.myhost.com/subdomain1/otherStuff

To:

subdomain1.myhost.com/otherStuff

 

Oct 7, 2009 at 9:58 PM

The problem comes with google adwords.

We have to make a link to subdomain1.myhost.com/otherStuff in an advertisement, but we can't put subdomain1.myhost.com 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 www.myhost.com in the "host" field, but then Google didn't allow us to put a link to subdomain1.myhost.com/otherStuff 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.

Coordinator
Oct 8, 2009 at 6: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 subdomain.myhost.com .   Why can you not link to www.myhost.com?   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 www.myhost.com.

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