Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

url rewriting - URL Rewrite of a subdirectory to a different domain using IIS

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...