URL Rewrite- Part 1(Prerequisites)
I am planning to post of a series of blogs on how we can use URLRewrite with and without ARR in IIS 7 and above. But before going into URLRewrite we need to understand some basics and there are some prerequisites. So in this blog we will discuss about the prerequisites below.
1) Difference between Rewrite and Redirect
2) Scope of Rewrite with ARR
3) Scope of Rewrite without ARR
4) Regular Expressions
Difference between Rewrite and Redirect:
Redirect:
Consider a scenario where we had an application ‘old1’ (https://bing.com/old1/) which was the old location and the content has now been moved to https://bing.com/new1/ , this can be done in two ways.
Also observe that when we use redirect client(IE for instance) knows that the url got changed and you will see a change in url in the client (browser)
Rewrite:
Consider the same scenario where we had an application ‘old1’ (https://bing.com/old1/) which was the old location and the content has now been moved to https://bing.com/new1/ , rewrite works as below.
Over here client (for instance IE) doesn’t know that resource has changed, so the URL wont change in the client (browser).
Scope of Rewrite with ARR
With Arr URlRewrite can be used to rewrite requests to any site within the same server or any site in any backend server. To achieve this urlrewrite rules have to be created at the server level.
Scope of Rewrite without ARR
• Without ARR URLRewrite can be used to rewrite requests to any other resource within the site. We can’t rewrite requests to a different site or server.
• For eg: https://bing.com rewritten to https://bing.com/new/ or https://bing.com/a.aspx to https://bing.com/b.aspx. We cant rewrite requests from https://bing.com/* to https://Chiranth.com/
• For this url rewrite rules are created at the site level or at the application level within the site.
Regular Expressions:
A regular expression (regex or regexp for short) is a special text string for describing a search pattern.
- . – 0 or 1 occurrence of any character
Eg: If I specify . It matches 0-9, a-z or any character
- * - specify 0 or more occurrence of previous character
Eg: If I specify s* ; null,s,ss,sss,ssssss,etc matches the pattern
- .* - means it matches null or any word or any series of characters
For eg: .* matches null value,start,match,a.aspx,etc.
- ^ - means starts with
For eg: ^s.* matches to start,snap,s, anything that starts with s.
- $ - means ends with
For eg: .*s$ matches with s,paas,saas,iaas anything that ends with s.
- + - one or more occurrence of previous character.
Eg: s+ matches with s,ss,sss,etc
1. ?- matches 0 or only one occurrence of the previous character
eg: a? matches a, s? matches s
1. if your text pattern contains any of the above special characters and you want to remove the special meaning of the special characters then you can use a backslash before the special character.
\{specialcharacter}
Eg: \. matches . , \? matches ?, \* matches *
You will find a lot of resources in the internet for regular expressions.
I will release my next blog on how to create inbound rules, outbound rules, and rewrite maps shortly.
Technorati Tags: urlrewrite,regular expressions,rewrite,redirect,arr,IIS
Comments
- Anonymous
June 10, 2014
Those first two images (Redirect / Rewrite) appear to be the same (Redirect)? - Anonymous
June 11, 2014
@Tim: Sorry my bad. thanks for pointing it out. i have changed it - Anonymous
June 11, 2014
Thanks - Anonymous
June 11, 2014
In case anyone doesn't know, ARR = Application Request Routing. - Anonymous
June 11, 2014
Quick question, when you say urlrewrite, you are referring to the IIS add-in module called "URL Rewrite", correct? The one that doesn't come with IIS 7.5 but can be easily added. - Anonymous
June 11, 2014
This was indeed helpful, looking forward for next update - Anonymous
June 11, 2014
@James:ya its the addon module that can be added to iis 7.0 and onwards - Anonymous
March 29, 2015
Good article & best for beginners!!