URL Rewrite of a subdirectory to a different domain using IIS

老子叫甜甜 提交于 2019-11-28 05:21:22

问题


GOAL #1: www.web1.com/web2 needs to point to www.web2.com

GOAL #2: Users must always see www.web1.com/web2 and the paths & queries in web2

For example: www.web1.com/web2/login OR www.web1.com/web2/?query=string

www.web1.com is on IIS6 (using ISAPI Rewrite) www.web2.com is on IIS8 (using URL Rewrite & ARR)

Can someone guide me on how I should go about this?

=======================

On web1, I used the following:

RewriteCond %{HTTP_HOST} ^www.web1.com$

RewriteRule ^/web2/?$ www.web2.com [NC,P,R=301,L]

On web2, I setup an ARR server farm and have created an inbound rule.

However, when I pull www.web1.com/web2, the URL on the browser still says www.web2.com. I've played around with using the REVERSE PROXY and the OUTBOUND. I've watched most of Scott Forsyth's videos and read his articles. I feel I'm skipping something.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/22392522/url-rewrite-of-a-subdirectory-to-a-different-domain-using-iis

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