使用 IIS 将子目录的 URL 重写为不同的域 [英] URL Rewrite of a subdirectory to a different domain using IIS

查看:23
本文介绍了使用 IIS 将子目录的 URL 重写为不同的域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标 #1:www.web1.com/web2 需要指向 www.web2.com

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

目标 #2:用户必须始终看到 www.web1.com/web2 和路径 &web2中的查询

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

例如:www.web1.com/web2/login OR www.web1.com/web2/?query=string

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

www.web1.com 在 IIS6 上(使用 ISAPI 重写)www.web2.com 在 IIS8 上(使用 URL 重写和 ARR)

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?

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

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

在 web1 上,我使用了以下内容:

On web1, I used the following:

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

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

重写规则 ^/web2/?$ www.web2.com [NC,P,R=301,L]

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

在 web2 上,我设置了一个 ARR 服务器群并创建了一个入站规则.

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

但是,当我拉 www.web1.com/web2 时,浏览器上的 URL 仍然显示 www.web2.com.我已经尝试过使用 REVERSE PROXY 和 OUTBOUND.我观看了大部分 Scott Forsyth 的视频并阅读了他的文章.我觉得我在跳过一些东西.

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.

推荐答案

在 IIS7 和 IIS8 上使用 URL REWRITE 解决了这个问题.(我今天将在 IIS6 上的 ISAPI REWRITE 上应用它,并将更新我的帖子.)

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.)

在 WEB1 服务器上(在 IIS7 上):

ON WEB1 SERVER (on IIS7):

在站点级别,添加入站规则.(对于新手,运行 IIS 并单击我的 WEB1 版本.双击右侧图标列表中的 URL REWRITE.单击右侧列表中的 ADD RULE.)

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. 在入站规则下,选择空白规则
  2. 给它一个名字,任何你想要的名字(即子目录重写")
  3. 在模式下,输入 ^web2$|^web2/(.*)
  4. 在条件下,点击添加
  5. 条件输入:{HTTP_HOST}
  6. 模式:^web1.com$
  7. 在操作下,选择操作类型:重写
  8. 重写 URL:http://www.web2.com/{R:1}
  9. 点击应用

<小时>

在 WEB1 服务器上(在 IIS6 上):


ON WEB1 SERVER (on IIS6):

使用 Helicon ISAPI_Rewrite 3 付费版

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

<小时>

在 WEB2 服务器上(在 IIS8 上):


ON WEB2 SERVER (on IIS8):

在站点级别,添加出站规则.

On the site level, add OUTBOUND RULE.

  1. 在出站规则下,选择空白规则
  2. 给它一个名字,任何你想要的名字(即重写路径")
  3. 在前提条件下,选择创建新前提条件
  4. 名称:isHTHML
  5. 点击添加
  6. 条件输入:{RESPONSE_CONTENT_TYPE}
  7. 模式:^text/html
  8. 在 MATCH 下,选中匹配内容"下的所有复选框
  9. 模式:^/(.*)
  10. 在 ACTION 下,操作类型:重写
  11. 值:/web2/{R:1}
  12. 点击应用

  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:感谢 Scott Forsyth 的启发.

PS: Thanks to Scott Forsyth for the inspiration.

这篇关于使用 IIS 将子目录的 URL 重写为不同的域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆