Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between IIS Redirect and Rewrite (in relation to redirecting)

The question may sound odd, but given an article, it is definitely possible to use the rewrite module to perform redirects just as with the redirect module. Both are able to issue a permanent redirect (301).

There is a question asking for the difference, but it talks about the rewrite module being used to purely rewrite not redirect. Another post makes this clear, but doesn't seem to get an adequate answer.

Hence, my question: What's the difference between these modules? Which is preferred over the other when it comes to redirects?

like image 653
Matthias Avatar asked Apr 15 '14 07:04

Matthias


People also ask

What does IIS rewrite do?

IIS URL Rewrite 2.1 enables Web administrators to create powerful rules to implement URLs that are easier for users to remember and easier for search engines to find. By using rule templates, rewrite maps, .

What is IIS redirect?

The <httpRedirect> element configures settings for Internet Information Services (IIS) 7 that redirect client requests to a new location. There are several reasons why you might want to redirect clients to a new location.

What is the difference between routing and URL rewriting?

URL rewriting is focused on mapping one URL (new url) to another URL (old url) while routing is focused on mapping a URL to a resource. Actually, URL rewriting rewrites your old url to new one while routing never rewrite your old url to new one but it map to the original route.

Why do we need URL Rewrite?

URL rewriting allows URLs to be more easily remembered by the user. When the URL is entered into the Web server, the URL rewrite engine modifies the syntax behind the scenes to enable the appropriate Web page or database item to be retrieved.


1 Answers

NOTE: THIS ANSWER DOES NOT answer difference between IIS Redirect (httpRedirect) vs URL Rewrite Module's Redirect but rather difference between URL Rewrite Module's (redirect vs rewrite).

If you are trying to hide complex URL (with querystrings) to more friendly URLs then Rewrite is the way to go as browser/Search Engines will always see 200OK and assume the content is coming from requested original URL.

If you are trying to indicate a change of resource to search engines/users of new URL then Redirect is the way to go as you are sending 301 status code saying that resource has moved from original to this new location.

IIS Redirect:

  • Redirecting happens at Client Side
  • Browser sees a different URL In address bar.
  • Client aware of a redirect URL.
  • 301/302 can be issued. Edit: (303/307 can be issued too)
  • Good for SEO/Search Engine to indicate of new URL. mysite.com/abc to mysite.com/pqr
  • Can be redirected to same site or different site altogether.

IIS Rewrite:

  • Redirecting happens at Server Side
  • Browser does not see new URL in address bar.
  • Client unaware if content is served from a re-written URL.
  • No 301/302 are issued. This will have normal 200 OK assuming that rewritten URL Resource is available.
  • Good to hide unfriendly URL and also SEO. mysite.com/article/test-sub/ to mysite.com/article.aspx?id=test-sub
  • Generally for a resource within same site.

Request Handling (REDIRECT): www.mysite.com/abc to redirect to www.mysite.com/pqr

  1. Client calls: www.mysite.com/abc
  2. URL Rewrite Module sees a rule match for client URL and gives new redirect URL.
  3. Server responds with 301 with new URL for client to call www.mystite.com/pqr
  4. Client calls new URL www.mystite.com/pqr
  5. Server responds with 200 OK for new URL. (address bar shows new URL)

Request Handling (REWRITE): www.mysite.com/abc which you want to point to www.mysite.com/pqr

  1. Client calls: www.mysite.com/abc
  2. URL Rewrite Module sees a rule match and provides new rewritten url to IIS i.e. www.mysite.com/pqr and Server makes request for that URL within IIS.
  3. Server responds with 200 OK for original URL but with content from rewritten url. (address bar shows original URL and client does not know that you are serving content from different URL)
like image 186
bdoshi Avatar answered Sep 21 '22 15:09

bdoshi