Iis – HTTP Redirect versus URL Rewrite (IIS)

iisredirectrewritewindows-server-2012-r2

In the IIS menu you have HTTP Redirect and URL Rewrite. The latter then has a rewrite action and a redirect action. I'm wondering what is the difference between all these.

Best Answer

HTTP redirect is a module that does HTTP redirection, which is a 300-level response with a Location header. Browsers read this 300-level reaponse, parse the Location header and redirect to the specified address. Visually we see the browser’s address change.

The URL’s redirect action type is the exact same as the HTTP redirection, in terms of the end result. However, with URL rewrite, we can make more complex redirection rules that what I have been able to do with HTTP redirect.

Rewriting the URL causes the URL to be rewritten to other values prior to the many of the modules running. This causes the execution to be performed based on the changed URL instead of the original one. This is entirely server sided, so browser receives an HTTP response in the end. If the responses are not a 300 level response, we would not even see the URL change in the browser.

Rewrite example

Let’s say you have an ASP.NET Web Forms page that has a /Users.aspx?id=3 page to look up User 3’s information. We would create a rule that matches ^users/(\d+)$ and have this rule rewrite to /user.aspx?id={R:1}. This causes a URL like http://server/users/3 to be handled internally as http://server/users.aspx?id=3. The browser would no see an address change.

Same example with redirection

If the rule above were a redirect rule. The URL /users/3 would cause a 300-level response with the Location header set to /users.apsx?id=3 and the browser would navigate to this page. We would see the browser’s address to http://server/users.aspx?id=3