小编wit*_*ith的帖子

为什么这个 IIS7 重写执行重定向?

我有一个重写规则响应 301 重定向,但我不知道为什么。

我在 WinHost 共享主机上,使用 IIS 7 重写来托管我从我帐户的子文件夹拥有的另一个域。

默认情况下,WinHost 会将您的其他域指向您帐户的根目录。所以我的目标有两个:

  1. 我想将这些其他域文件物理分开放在一个子文件夹中
  2. 我想从地址栏中隐藏所述子文件夹

以便:

http://myotherdomain.com
Run Code Online (Sandbox Code Playgroud)

从以下位置获取服务:

E:\account_root\myotherdomain
Run Code Online (Sandbox Code Playgroud)

所以使用 IIS 7 重写模块,我生成了这个规则。

<xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Test" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="(^|\.)myotherdomain\.com$" />
                    </conditions>
                    <action type="Rewrite" url="myotherdomain/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我希望请求myotherdomain.com偏移到myotherdomain子文件夹中。

这是有效的,但前提是请求中没有路径。如果我请求,http://myotherdomain.com我会收到 200 响应 & 在我的浏览器中,我会看到位于E:\account_root\myotherdomain. 不会发生重定向。

如果您向请求添加路径,例如http://myotherdomain.com/test,现在我会收到一个 301 重定向到重写的 URL:

Response: HTTP/1.1 301 Moved Permanently
Location: http://myotherdomain.com/myotherdomain/test/
Run Code Online (Sandbox Code Playgroud)

然后浏览器获取:

Request: GET …
Run Code Online (Sandbox Code Playgroud)

iis-7 redirect

2
推荐指数
1
解决办法
2306
查看次数

标签 统计

iis-7 ×1

redirect ×1