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

荒凉一梦 提交于 2019-12-07 16:33:21

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/23077741/difference-between-iis-redirect-and-rewrite-in-relation-to-redirecting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!