问题
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.)
- Under INBOUND RULES, select BLANK RULE
- Give it a name, any name you want (ie, "Subdirectory Rewrite")
- Under PATTERN, type ^web2$|^web2/(.*)
- Under CONDITION, click ADD
- Condition Input: {HTTP_HOST}
- Pattern: ^web1.com$
- Under ACTION, select Action Type: Rewrite
- Rewrite URL: http://www.web2.com/{R:1}
- Click APPLY
ON WEB1 SERVER (on IIS6):
Use Helicon ISAPI_Rewrite 3 paid version
- RewriteCond Host: (.*)
- RewriteRule ^/web2(/.*)?$ http://www.web1.com/web2$1 [P]
ON WEB2 SERVER (on IIS8):
On the site level, add OUTBOUND RULE.
- Under OUTBOUND RULES, select BLANK RULE
- Give it a name, any name you want (ie, "Rewrite Path")
- Under PRECONDITION, select Create New Precondition
- Name: isHTHML
- Click ADD
- Condition Input: {RESPONSE_CONTENT_TYPE}
- Pattern: ^text/html
- Under MATCH, select all the checkboxes under "Match the content within"
- Pattern: ^/(.*)
- Under ACTION, Action Type: Rewrite
- Value: /web2/{R:1}
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