Conditional logic with IIS redirects: possible?

Conditional logic with IIS redirects: possible?

am 05.11.2007 12:00:53 von cffan3

Hi,

I have a single webserver instance, blank host header. However I have
many domains pointing to it, a rather standard set up where seemingly
different sites share the same code base. It's the codebase that does
the job of showing the right data based on the host.

So, if I want to add a redirect using virtual directories, the issue I
face is that all sites share the redirect. There is no way for me to
say 'if the site is www.mysite.com' then this URL redirect should go
there. If not, go elsewhere'. Which is a big problem for me because
one of my sites needs many redirects, and sharing its redirects with
other smaller sites would not be appropriate (as users / google
spider / etc might accidently stumble on them).

So far I've been working around the issue by implementing the
redirects via code. But as my list of redirect grows it's becoming
impossible (and ugly) to manage.

Is there a way, either via the stock version of IIS or via some form
of plugin or extension, to implement conditional logic based on the
host header of a request?

Any help or pointer would be much appreciated! TIA!

Re: Conditional logic with IIS redirects: possible?

am 05.11.2007 12:09:47 von Ken Schaefer

Erm,

If you use Regular Expressions, or similar, in your code, then it wouldn't
be a maintenance nightmare. Assuming that the virtual directories you need
to redirect to have some defined relationship with the HTTP Host header sent
by the client. If there's a 1:1 mapping, you could do something like:

(this is untested psuedo-code):

strHostHeader = Request.ServerVariables("HTTP_Host")
Response.Redirect("/" & strHostHeader)

Cheers
Ken

--
My IIS Blog: www.adOpenStatic.com/cs/blogs/ken

wrote in message
news:1194260453.962275.57240@k79g2000hse.googlegroups.com...
> Hi,
>
> I have a single webserver instance, blank host header. However I have
> many domains pointing to it, a rather standard set up where seemingly
> different sites share the same code base. It's the codebase that does
> the job of showing the right data based on the host.
>
> So, if I want to add a redirect using virtual directories, the issue I
> face is that all sites share the redirect. There is no way for me to
> say 'if the site is www.mysite.com' then this URL redirect should go
> there. If not, go elsewhere'. Which is a big problem for me because
> one of my sites needs many redirects, and sharing its redirects with
> other smaller sites would not be appropriate (as users / google
> spider / etc might accidently stumble on them).
>
> So far I've been working around the issue by implementing the
> redirects via code. But as my list of redirect grows it's becoming
> impossible (and ugly) to manage.
>
> Is there a way, either via the stock version of IIS or via some form
> of plugin or extension, to implement conditional logic based on the
> host header of a request?
>
> Any help or pointer would be much appreciated! TIA!
>

Re: Conditional logic with IIS redirects: possible?

am 05.11.2007 13:17:43 von cffan3

On Nov 5, 11:09 am, "Ken Schaefer"
wrote:
> Erm,
>
> If you use Regular Expressions, or similar, in your code, then it wouldn't
> be a maintenance nightmare. Assuming that the virtual directories you need
> to redirect to have some defined relationship with the HTTP Host header sent
> by the client. If there's a 1:1 mapping, you could do something like:
>
> (this is untested psuedo-code):
>
> strHostHeader = Request.ServerVariables("HTTP_Host")
> Response.Redirect("/" & strHostHeader)
>
> Cheers
> Ken
>
> --
> My IIS Blog:www.adOpenStatic.com/cs/blogs/ken
>
> wrote in message
>
> news:1194260453.962275.57240@k79g2000hse.googlegroups.com...
>
> > Hi,
>
> > I have a single webserver instance, blank host header. However I have
> > many domains pointing to it, a rather standard set up where seemingly
> > different sites share the same code base. It's the codebase that does
> > the job of showing the right data based on the host.
>
> > So, if I want to add a redirect using virtual directories, the issue I
> > face is that all sites share the redirect. There is no way for me to
> > say 'if the site iswww.mysite.com'then this URL redirect should go
> > there. If not, go elsewhere'. Which is a big problem for me because
> > one of my sites needs many redirects, and sharing its redirects with
> > other smaller sites would not be appropriate (as users / google
> > spider / etc might accidently stumble on them).
>
> > So far I've been working around the issue by implementing the
> > redirects via code. But as my list of redirect grows it's becoming
> > impossible (and ugly) to manage.
>
> > Is there a way, either via the stock version of IIS or via some form
> > of plugin or extension, to implement conditional logic based on the
> > host header of a request?
>
> > Any help or pointer would be much appreciated! TIA!

Good point, however, here's the problem: the directories need to exist
for the code to trigger. For example, if I want the /test directory to
redirect to /index.asp&theredirect=test, then the user must be
accessing the /test directory for the code in the /test directory to
run. When the user type www.mysite.com/test, iis is the first on to
run and of course will give a 404 if the /test directory doesn't
exist.

Re: Conditional logic with IIS redirects: possible?

am 05.11.2007 16:15:07 von .._..

Why aren't you using host headers?

I think you are going to have to write an ISAPI filter to do what you
describe.

wrote in message
news:1194260453.962275.57240@k79g2000hse.googlegroups.com...
> Hi,
>
> I have a single webserver instance, blank host header. However I have
> many domains pointing to it, a rather standard set up where seemingly
> different sites share the same code base. It's the codebase that does
> the job of showing the right data based on the host.
>
> So, if I want to add a redirect using virtual directories, the issue I
> face is that all sites share the redirect. There is no way for me to
> say 'if the site is www.mysite.com' then this URL redirect should go
> there. If not, go elsewhere'. Which is a big problem for me because
> one of my sites needs many redirects, and sharing its redirects with
> other smaller sites would not be appropriate (as users / google
> spider / etc might accidently stumble on them).
>
> So far I've been working around the issue by implementing the
> redirects via code. But as my list of redirect grows it's becoming
> impossible (and ugly) to manage.
>
> Is there a way, either via the stock version of IIS or via some form
> of plugin or extension, to implement conditional logic based on the
> host header of a request?
>
> Any help or pointer would be much appreciated! TIA!
>

Re: Conditional logic with IIS redirects: possible?

am 05.11.2007 19:11:18 von Kristofer Gafvert

Hi,

You can configure IIS so ISAPI extensions/filters can handle requests
without folders/files physically exists.

Whatever server side technology you use must however handle this properly
(ASP.NET 2.0 does).

As an alternative, ISAPI Rewrite is a popular product that can do this.

http://www.isapirewrite.com/


--
Regards,
Kristofer Gafvert
http://www.gafvert.info/iis/ - IIS Related Info


cffan3@gmail.com wrote:

>On Nov 5, 11:09 am, "Ken Schaefer"
>wrote:
>>Erm,
>>
>>If you use Regular Expressions, or similar, in your code, then it wouldn't
>>be a maintenance nightmare. Assuming that the virtual directories you need
>>to redirect to have some defined relationship with the HTTP Host header
>>sent
>>by the client. If there's a 1:1 mapping, you could do something like:
>>
>>(this is untested psuedo-code):
>>
>>strHostHeader = Request.ServerVariables("HTTP_Host")
>>Response.Redirect("/" & strHostHeader)
>>
>>Cheers
>>Ken
>>
>>--
>>My IIS Blog:www.adOpenStatic.com/cs/blogs/ken
>>
>> wrote in message
>>
>>news:1194260453.962275.57240@k79g2000hse.googlegroups.com. ..
>>
>>>Hi,
>>
>>>I have a single webserver instance, blank host header. However I have
>>>many domains pointing to it, a rather standard set up where seemingly
>>>different sites share the same code base. It's the codebase that does
>>>the job of showing the right data based on the host.
>>
>>>So, if I want to add a redirect using virtual directories, the issue I
>>>face is that all sites share the redirect. There is no way for me to
>>>say 'if the site iswww.mysite.com'then this URL redirect should go
>>>there. If not, go elsewhere'. Which is a big problem for me because
>>>one of my sites needs many redirects, and sharing its redirects with
>>>other smaller sites would not be appropriate (as users / google
>>>spider / etc might accidently stumble on them).
>>
>>>So far I've been working around the issue by implementing the
>>>redirects via code. But as my list of redirect grows it's becoming
>>>impossible (and ugly) to manage.
>>
>>>Is there a way, either via the stock version of IIS or via some form
>>>of plugin or extension, to implement conditional logic based on the
>>>host header of a request?
>>
>>>Any help or pointer would be much appreciated! TIA!
>
>Good point, however, here's the problem: the directories need to exist
>for the code to trigger. For example, if I want the /test directory to
>redirect to /index.asp&theredirect=test, then the user must be
>accessing the /test directory for the code in the /test directory to
>run. When the user type www.mysite.com/test, iis is the first on to
>run and of course will give a 404 if the /test directory doesn't
>exist.