我正在尝试重写 url 以更改请求,例如
到
我已经像这样将我的 URL 重写规则弹出到 Web 配置中
<rewrite>
<rules>
<rule name="SiteReWrite" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://bar.com/{C:1}/"/>
<conditions>
<add input="{HTTP_HOST}" pattern="(.*)\.bar\.com" />
</conditions>
</rule>
</rules>
</rewrite>
但我收到 404.4 错误。查看跟踪日志文件,我在其中看到了这个
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="WWW Server" Guid="{3A2A4E84-4C21-4981-AE10-3FDA0D9B0F83}"/>
<EventID>0</EventID>
<Version>1</Version>
<Level>4</Level>
<Opcode>42</Opcode>
<Keywords>0x0</Keywords>
<TimeCreated SystemTime="2012-12-03T05:54:01.237Z"/>
<Correlation ActivityID="{00000000-0000-0000-1000-0080030000FC}"/>
<Execution ProcessID="7312" ThreadID="3180"/>
<Computer>ULTRA</Computer>
</System>
<EventData>
<Data Name="ContextId">{00000000-0000-0000-1000-0080030000FC}</Data>
<Data Name="OldUrl">/</Data>
<Data Name="NewUrl">http://bar.com/foo/</Data>
</EventData>
<RenderingInfo Culture="en-US">
<Opcode>URL_CHANGED</Opcode>
</RenderingInfo>
<ExtendedTracingInfo xmlns="http://schemas.microsoft.com/win/2004/08/events/trace">
<EventGuid>{D42CF7EF-DE92-473E-8B6C-621EA663113A}</EventGuid>
</ExtendedTracingInfo>
</Event>
从 NewUrl 看起来一切都很美好。注意,看起来这个实例被缓存了,但我在之前的事件中看到了规则匹配。
如果我输入网址http://bar.com/foo/它应该可以正常工作。我不希望用户看到新的 url,他们应该认为他们在 foo.bar.com 而不是 bar.com/foo。这只是我在 mvc 应用程序中的一些路由。
有谁知道它为什么会出现这种奇怪的行为?我为此使用 IIS express 8,我还没有尝试使用 IIS。