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.

10,035 views

ruslany on March 11th 2010 in URLRewrite

PoorFairAverageGoodExcellent (11 votes, average: 3.55 out of 5)

27 Responses to “IIS URL Rewrite 2.0 – Release to Web”

  1. Gravatar ImageAndy responded on 13 Mar 2010 at 12:40 pm #

    This is great news that we have RTW!

  2. Gravatar Imagehumairm responded on 13 Mar 2010 at 7:37 pm #

    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!

  3. Gravatar Imageruslany responded on 13 Mar 2010 at 8:48 pm #

    @humairm: Could you XML encode the rewrite rule before posting it? Otherwise WordPress filters out XML markup.

  4. Gravatar Imagehumairm responded on 14 Mar 2010 at 6:37 pm #

    <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>

  5. Gravatar Imagehumairm responded on 14 Mar 2010 at 6:49 pm #

    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

  6. Gravatar Imageruslany responded on 15 Mar 2010 at 10:07 am #

    @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.

  7. Gravatar Imagehumairm responded on 15 Mar 2010 at 7:44 pm #

    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!

  8. Gravatar Imagesvk responded on 24 Mar 2010 at 11:32 am #

    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?

  9. Gravatar Imageruslany responded on 25 Mar 2010 at 1:58 pm #

    @svk: If you do not need any of the new features, then there is no need for you to upgrade from 1.1.

  10. Gravatar ImageBelial responded on 07 Jul 2010 at 11:15 am #

    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?

  11. Gravatar ImageMyBestGuess responded on 14 Jul 2010 at 5:38 am #

    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.

  12. Gravatar ImageMyBestGuess responded on 14 Jul 2010 at 5:41 am #

    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

  13. Gravatar Imageruslany responded on 14 Jul 2010 at 10:42 am #

    Hi MyBestGuess. The rule looks correct. I would suggest to enable Failed Request Tracing and check if the rule gets executed at all.

  14. Gravatar ImageWright responded on 19 Aug 2010 at 10:18 am #

    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

  15. Gravatar ImageRaman responded on 19 Aug 2010 at 11:44 pm #

    I have static compression enabled on my server. There are no outbound rules. There are only redirect rules. Like data.ramansingla.com/index.html is redirected to http://www.ramansingla.com/data/index.html

    I checked the returned headers. Those don’t show content-encoding: gzip. Should I do something differently?

  16. Gravatar Imageruslany responded on 27 Aug 2010 at 1:42 pm #

    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.

  17. Gravatar Imageruslany responded on 27 Aug 2010 at 1:44 pm #

    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.

  18. Gravatar ImageAndreas Andreou responded on 05 Sep 2010 at 5:07 pm #

    Hi,
    do you know if it’s possible for a rule in a subfolder (i.e. defined in somefolder/web.config) to take precedence over a rule defined in the root folder (i.e. in web.config)?

  19. Gravatar Imageruslany responded on 05 Sep 2010 at 6:21 pm #

    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.

  20. Gravatar ImageAndreas Andreou responded on 05 Sep 2010 at 7:06 pm #

    thx ruslany
    I couldn’t find any related documentation online – even the xml schema for the rules would have helped! So, your help is much appreciated.

  21. Gravatar ImageAli responded on 27 Sep 2010 at 1:37 am #

    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.

  22. Gravatar Imageruslany responded on 27 Sep 2010 at 9:05 pm #

    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.

  23. Gravatar ImageAli responded on 01 Oct 2010 at 8:01 am #

    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.

  24. Gravatar ImageKen responded on 18 Nov 2010 at 7:03 pm #

    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?

  25. Gravatar Imageeddy responded on 18 Jan 2011 at 5:42 am #

    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

  26. Gravatar ImageKarim Momtaz responded on 06 Aug 2012 at 2:52 am #

    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!

  27. Gravatar ImageReinhard responded on 11 Oct 2012 at 6:55 am #

    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

Trackback URI | Comments RSS

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

XML Markup: If You want to add XML code to the comment please XML encode it first, otherwise the code will not show up.

Recently Published Articles