Search code examples
bindingurl-rewritingroutesurl-routingiis-6

Changing behavior based on port# on same IIS site


Let's say I have requests coming into my IIS site on two different ports. Can I direct one port to serve www.website.com and another to www.website.com/subfolder?

I'm trying to do some georouting without having more than one webserver or site. I have AWS Route-53 set up to send traffic based on region to different load balancers that will take traffic from one region and send to port 2000, and from a different region to port 2001. www.website.com has content geared for the first region, but www.website.com/subfolder is our content for the other region. Since AWS can split up the traffic for me based on location and send to different ports of my choosing, is there anyway to use that to route or redirect requests to different folders on the same site?

EDIT: I think the way to do this is with a URL redirect rule, with a condition for {SERVER_PORT} specifying the port like so:

Match URL: Matches Pattern: .*

Condition: {SERVER_PORT} Matches Pattern 2001

Action Type: Redirect URL: subfolder/{R:0} Type: Permanent (301)

This should route everything coming in on port 2001 to my subfolder but not the traffic on other ports, correct? The site CMS already arranges everything so that www.website.com/(anything) and www.website.com/subfolder/(anything) will display the same content, with changes appropriate to the region.


Solution

  • So this works with the Redirect rule I assigned above. Since it broke a few includes, like stylesheets and whatnot, I also added some exclusions with {PATH_INFO} tag, and there needed to be a rule to exclude URLs that already had subfolder/ in them, using the {HTTP_URL} condition, to prevent the redirect from looping forever and giving you www.website.com/subfolder/subfolder/subfolder.... etc.