URL Rewrite of a subdirectory to a different domain using IIS

喜欢而已 提交于 2019-11-29 11:41:56
happy297

Figured it out using URL REWRITE on IIS7 and IIS8. (I will apply this on the ISAPI REWRITE on IIS6 today and will update my post.)


ON WEB1 SERVER (on IIS7):

On the site level, add INBOUND RULE. (For newbies, run IIS and click on your version of my WEB1. Double-click on URL REWRITE from the list of icons on the right. Click on ADD RULE from the list on the right.)

  1. Under INBOUND RULES, select BLANK RULE
  2. Give it a name, any name you want (ie, "Subdirectory Rewrite")
  3. Under PATTERN, type ^web2$|^web2/(.*)
  4. Under CONDITION, click ADD
  5. Condition Input: {HTTP_HOST}
  6. Pattern: ^web1.com$
  7. Under ACTION, select Action Type: Rewrite
  8. Rewrite URL: http://www.web2.com/{R:1}
  9. Click APPLY

ON WEB1 SERVER (on IIS6):

Use Helicon ISAPI_Rewrite 3 paid version

  1. RewriteCond Host: (.*)
  2. RewriteRule ^/web2(/.*)?$ http://www.web1.com/web2$1 [P]

ON WEB2 SERVER (on IIS8):

On the site level, add OUTBOUND RULE.

  1. Under OUTBOUND RULES, select BLANK RULE
  2. Give it a name, any name you want (ie, "Rewrite Path")
  3. Under PRECONDITION, select Create New Precondition
  4. Name: isHTHML
  5. Click ADD
  6. Condition Input: {RESPONSE_CONTENT_TYPE}
  7. Pattern: ^text/html
  8. Under MATCH, select all the checkboxes under "Match the content within"
  9. Pattern: ^/(.*)
  10. Under ACTION, Action Type: Rewrite
  11. Value: /web2/{R:1}
  12. Click APPLY

    PS: Thanks to Scott Forsyth for the inspiration.

I'd say "P" and "R=301" are a bit controversial. It's like "I am John and Mary". Use [P] to make a simple proxy rule.

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