我有一个重写规则响应 301 重定向,但我不知道为什么。
我在 WinHost 共享主机上,使用 IIS 7 重写来托管我从我帐户的子文件夹拥有的另一个域。
默认情况下,WinHost 会将您的其他域指向您帐户的根目录。所以我的目标有两个:
以便:
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 /myotherdomain/test/ HTTP/1.1
Run Code Online (Sandbox Code Playgroud)
然后重写规则再次在 IIS 上运行,最终 IIS 尝试为位于以下位置的默认文档提供服务:
E:\account_root\myotherdomain\myotherdomain\test
Run Code Online (Sandbox Code Playgroud)
哪个不存在:
Response: HTTP/1.1 404 Not Found
Run Code Online (Sandbox Code Playgroud)
所以重写本身似乎是有效的;我不明白的是为什么 IIS 将 301 重定向放入混合中,但仅当请求中存在路径时。
归档时间: |
|
查看次数: |
2306 次 |
最近记录: |