IIS URL Rewrite 2.0 – Release to Web

The IIS URL Rewrite Module 2.0 – RTW is available for download. IIS URL Rewrite v2.0 is an incremental release that includes all the features from version 1.1, and adds extensibility support and outbound response rewriting. More specifically, v2.0 can be used to:

  • Express complex URL rewriting logic by using custom rewrite providers written in .NET.
  • Replace the URLs generated by a web application in the response HTML with a more user friendly and search engine friendly equivalent
  • Fix up the content of any HTTP response by using regular expression pattern matching.
  • Modify HTTP request and response headers and IIS server variables.

For the complete list of features available in this version, refer to Using URL Rewrite Module 2.0.

Install the URL Rewrite 2.0 – RTW

To install the URL Rewrite 2.0, use the download links at the module’s home page at http://www.iis.net/expand/urlrewrite. Note that this is a final, production ready release that is officially supported by Microsoft.

Upgrade notes:

  • If a previous version of URL Rewrite Module, such as v1.0 and v1.1, is already installed then it will be upgraded to the v2.0;
  • If an RC version of the URL Rewrite Module 2.0 is already installed, then it will be upgraded to RTW version.

Install the URL Rewrite Extensibility Samples

An important new feature in this release is the support for custom rewrite providers that can be written in .NET. Custom rewrite providers can be used to implement complex rewrite logic which cannot be expressed by using built-in rewriting functionality.

The URL Rewrite Extensibility Samples include the .NET assemblies and the source code implementing the following providers:

  • DbProvider – this provider can be used to retrieve rewrite mappings from a SQL Server database table by executing a stored procedure;
  • FileMapProvider – this provider can be used to retrieve rewrite mappings stored in a text file;
  • FileContainsProvider – this provider can be used to check if any string in a text file is a substring of the provider’s input string.

Download the URL Rewrite Extensibility Samples from MSDN Code Gallery.

More Information

The following documentation about URL Rewrite 2.0 is available on IIS.net:

Also, visit the URL Rewrite Forum on IIS.NET if you have run into any problems when using the module or have questions or suggestions.

34 thoughts on “IIS URL Rewrite 2.0 – Release to Web”

  1. Hi Ruslan – Not sure if this is a bug:

    I am using URL Rewrite 2.0 for HTTPS redirect using the following rule:

    The backreference {R:1} does not seem to be working. The URL I am testing is:

    http://www.server.com/XYZR2

    and I get the following redirect:

    https://www.server.com/

    I have ended up using https://{HTTP_HOST}/{HTTP_URL} as a workaround.

    Also in the previous versions documentation there was a section about the impact of server variables usage and output caching. {HTTPS} server variable was one of the variables that was not on the white list back then. Is that still the case? If yes how can I prevent the use of this variable and achieve a SSL redirect without compromising the output caching I have setup?

    Thanks!

  2. <rule name="Redirect to HTTPS" stopProcessing="true">
    <match url="(.*)" />
    <conditions trackAllCaptures="false">
    <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
    </rule>

  3. Ruslan – One other issue I have noticed is if I have a nested web application in IIS (XYZR2 is the parent and XYZR2/py is the nested) the nested application does not work with URL Rewrite (the parent application works fine). When I go to the URL Rewrite settings for the nested application I get an error message:

    Cannot add duplicate collection entry of type ‘rule’ with unique key attribute ‘name’ set to ‘Redirect to HTTPS’

    Although in the web.config there is only one entry for the element

  4. @himairm: I think that the reason you see this behavior with back-reference is that most probably you have the rewrite rule defined in web.config file located in the directory XYZR2 and this causes the module to give a relative path to the rewrite rule (i.e. with XYZR2 stripped off from the URL). Because of that the (.*) matches an empty string and hence the back-reference is empty. The rule will work if you put it in the web.config at the root folder of the website. The workaround that you have will also work, but I think you need to use {URL}, not {HTTP_URL}.

    Regarding the {HTTPS} variable – if you use it for the redirect rule then it should not matter. The output cache disabling logic is only applicable when using rewrite, not redirect.

    Regarding the error about unique key – Why do you need the same rule on two different levels? You can just create one “Redirect to HTTPs” rule in the root directory of the web site and it will take care of all the subdirectories and applications. The error is because you have a rule with the same name defined on two different configuration levels, which is not allowed.

  5. Hi Ruslan – Right on all counts; the URL Rewrite icon in IIS Management Console appearing for each subfolder was a bit confusing and I got started on the wrong track. I moved the web.config to the Root and all is working as expected. Thanks much for your response!

  6. If I am content with 1.1 features, is there a reason to upgrade to 2.0? Are there known bug fixes that would impact performance?

  7. i want to simulate my clients environment, application is served as HTTP but client demands HTTPS through middleman appliance that stablishes vpn/ssl connections, appliance rewrites all URLs and exposes the application to internet.

    example…
    http://lanServer/path/login.aspx
    appliance url rewrite…
    https://internetServer/path/login.aspx

    i want to debug some problems related to javascript, when accessing application from internet, is it possible to use iis7 url rewrite module to debug locally?

  8. Hello,

    I am using URL rewrite 2.0 to handle HTTPS redirects. I have the following code in my web.config setup through IIS and the website doesn’t get redirected or even throw a site required SSL error. It just loads like it normally would. I have made sure all SSL requirements have been made. Please help and let me know what I am doing wrong.

  9. Sorry, the code didn’t show. Here is my code that I am using.

    rewrite
    rules
    rule name=”Redirect to Https” stopProcessing=”true”
    match url=”(.*)”
    conditions
    add input=”{HTTPS}” pattern=”^OFF$”
    conditions
    action type=”Redirect” url=”https://{HTTP_HOST}/{URL}” redirectType=”SeeOther”
    rule
    rules
    rewrite

  10. Help… I have been researching this for days…

    In an earlier response to a blog you wrote: “URL rewriter processes global rules during PreBeginRequest pipeline stage.”

    I need to use the reverse proxy function of URL Rewriter, however at the same time I need to capture the in-comming request, inspect, and occasionally ALTER the content. How can I get infront of the URL Rewriter, alter some selected content, and then pass the altered content to the URL Rewriter / Reverse Proxy processes?

    (I seem to have full ability to alter the response returning to the browser using the IHttpModule interface. The request content is already processed by the URL Rewriter before it is available to me.)

    Any assistance would be appreciated.

    Bill

  11. Hi Raman,

    I think that for the response headers to show content-encoding, the request should contain header “accept-encoding”, e.g.

    Accept-Encoding: compress, gzip

    You can try to make request with this header by using WFetch.

  12. Hi Wright,

    One option I can think of is not to use global rules for reverse proxy. The reverse proxy can be implemented with normal distributed rules in web.config files.

    If you do that then I think you should be able to write an HTTP module that gets to the request before URL rewrite.

  13. Hi Andreas,

    Yes, it is possible. In the subfolder web.config file add the <clear/> elements at the beginning of the <rules> section. That way all the rules from the parent level will be removed and then you can add your subfolder rules.

    1. Ruslan,

      I had a thought that rules are only loaded from root web.config, in which scenario they can load from subfolder/web.config ?

      Thanks
      Naveed

  14. Hi ruslany – I was wondering if you’re aware of any differences in the Regex parsing/matching between 1.x and 2.0. I have a scenario which looks like there are differences as the same regex is matched in 1.1 and not matched in 2.0 for the same input.

    I’ve posted on iis.net (http://forums.iis.net/t/1171510.aspx) but haven’t had much luck getting to the bottom of the issue.

  15. Hi Ali,

    I am not aware of the differences between regex pattern matching between 1.1 and 2.0, but there might be some differences. URL rewrite uses the standard visual c++ regex library, which has had many bug fixes since v1.1 of URL rewrite was released.

    However, looking at the pattern example I do not understand why it has to be so complex. It tries to match the query string, which URL rewrite never uses as an input to the rewrite rule pattern. I would suggest simplifying the pattern.

    If you really have to have this pattern and do not need any of the URL rewrite 2.0 features (e.g. outbound url rewriting, setting of server variables, extensibilty) then you can continue using URL rewrite 1.1 – it is of a solid quality and has the same performance as v2.0.

  16. Thanks for the reply – really appreciate it. I’m going to look at rewriting the pattern – it’s a legacy pattern from the days of using ISAPI Rewrite, so it could definitely do with a rewrite. I’ll rollback to 1.1 while i investigate the pattern – I want to use 2.0 to modify response headers, so i need to get this working for 2.0.

    Thanks again for the response.

  17. I am using URL Rewrite 2.0 and have found that when using it as a reverse proxy it will automatically alter the response location header returned from a from an internal web site. I would like to disable this since the internal web site returns an internet facing location URL on the 301 redirect. How do I disable the automatic location response header?

  18. Hello ruslan,

    I am trying to convert my site with seourl using urlrewrite 2.0..
    Everything works in local system, but in the server, It is showing up error in the webconfig file, The configuration section ‘outboundRules’ cannot be read missing section declaration. The part of the webconfig is posted.

    <rewrite>
    <rules>
    <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
    <match url="^tutorial\.aspx$" />
    <conditions>
    <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
    <add input="{QUERY_STRING}" pattern="^id=([^=&amp;]+)&amp;title=([^=&amp;]+)$" />
    </conditions>
    <action type="Redirect" url="tutorial/{C:1}/{C:2}" appendQueryString="false" />
    </rule>
    <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
    <match url="^tutorial/([^/]+)/([^/]+)/?$" />
    <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="tutorial.aspx?id={R:1}&amp;title={R:2}" />
    </rule>
    </rules>
    <outboundRules>
    <rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1">
    <match filterByTags="A, Form, Img" pattern="^(.*/)tutorial\.aspx\?id=([^=&amp;]+)&amp;(?:amp;)?title=([^=&amp;]+)$" />
    <action type="Rewrite" value="{R:1}tutorial/{R:2}/{R:3}/" />
    </rule>
    </outboundRules>
    </rewrite>

    And one more, When i post back, the query strings are appended
    eventhough i had disabled append querystring

  19. Dear Ruslan,

    I’m using the IIS Url Rewrite with the rules posted on Waldek Blog
    And these are the rules as written in the web.config:

    My problem is: I have a login page, when I click on the login button, no validation fires and the page postback fails. And this error applies on any page that postback

    Any tip how to fix this bug! I searched a lot but nothing to handle this bug on IIS Rewrite!

    Thanks in advance!

  20. Dear Ruslan,

    after hours of searching I’d like to ask you directly for your help: I configured a URL rewrite fom IIS7 to a host running JBoss and tried to add the login user and his domain in the header area but unfortunately it does not work…

    Thanks in advance!
    Reinhard

  21. Hi Ruslany

    I’m wondering if you could help me out, I’m a bit new in IIS
    I’m trying to use URL Rewrite and so far not getting anywhere

    I want to shorten “http://mipayslip.mobi/xxx/xxx” to “http://mipayslip.mobi/”
    Below is my web.config

    Thank you in advance

  22. Hi Ruslan,

    The rewrite rules get cache for 30 sec and the DB provider not call to the database. How to increase rewrite cache. how the DBProvider CahceIntervalMinutes work?

  23. How can you connect to a remote SQL server for this since likely iis appPool\defaultappPool won’t be available?

Leave a Reply

Your email address will not be published. Required fields are marked *