URL Rewrite Outbound Rules–and ServerNameVariable-Part 14 of 52

As you may be guessing already, I’m a big fan of URL Rewrite for IIS.  Today I cover Outbound rules, providing demos on changing the content in-flight and adding Server Variables (HTTP headers) for the browser.

Also, in the 2nd half of the video I demo ServerNameVariable a URL Rewrite Provider add-on for making the server name available. See this blog post for further details and a download link.

This is week 14 of a 52 week series on various web administration related tasks. Past and future videos can be found here.

Having problems viewing on your mobile device?  Click here instead.


  • I have several web sites that have the URL of the other web sites in it. Right now, my users are logging into each of these web sites individually. My requirement is that I should provide one single domain name (or web site or URL) to it and refer to each of those web sites as a folder under the main domain.

    Current scenario:



    New scenario:



    For this, I am using ARR + URL Rewrite and have been sucessfull in getting this done. However, there is one major challenge where the application code / pages / HTML in App1 is referring to App2 as app2.mydomain.com/appurl/page.aspx.

    If the reference is within HREF or any specific tags, then the Outbound rule is sucessfully changing it to /app2/appurl/page.aspx, but my application does not necessarily refer to that through HREF or other tags.

    Instead, the value for the HREF and to refer elsewhere, is fetched from the database, that is, the URL app2.mydomain.com/app2/appurl/page.aspx is stored in DB, it fetches from DB and puts that in a JavaScript variable and refers to the application through the Variable name.

    In this case, since my outbound rule is tied up with the specific tags, looks for pattern and replaces, it is not able to find the URL inside the javascript variable. It is also not finding it in the general text. That is, in case I just show the application URL without hyperlinking that, this text should also ideally be changed by URL Rewrite. But that is also not happening.

    In one of the forums I saw that if I remove the "filterByTags" attribute in the match tag, it would find the text in the entire page and replace. But that is not working either. If I remove that attribute, the match pattern itself is failing and I see the reference to the original page name without any replacement of text anywhere. That is, even the hyperlinks are not being replaced. Then, everything below that rule is failing to execute

    Please help me out in this.


  • Hi Krishna,

    Good question. I've tried unsuccessfully in the past to parse the entire text but I haven't been able to get it working either. You may want to post a question here: http://forums.iis.net/1152.aspx

    However, I would warn that the resources to parse the entire body of every outgoing request would be pretty intense. If you can update your application to change the URL before you write it to the page, that may be a better long term solution for you. For example, your Javascript could use a relative URL or it could even dynamically use a value from a hidden tag, which you can change on the way out.

  • Hi Krishna. I don't know the URL Rewrite answer at this time, but what I recommend is to do one of two things:
    - Put the domain name in a hidden tag and in your JavaScript code, build the URL using that. Then it's very fast and clean to update the hidden value on the way out.
    - Add a server variable on the *incoming* request and then let your code return a different result based on what that variable is. Or, make the decision based on the HTTP_HOST which is already available to you.

  • Any suggestions on how to make this work in a web-farm shared config environment? My concern is that the config changes are made at the global level and I wont be able to get specific node headers returned.

Comments have been disabled for this content.