URL重写导致404
我设置了一个简单的规则来重写对我的域的所有请求:
<rule name="Rewrite Test" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="mydomain.com" />
</conditions>
<action type="Rewrite" url="http://mydomain.com/TestImage.jpg" appendQueryString="false" />
</rule>
启用此规则后,我每次访问我的域时都会收到 404 错误。但是,如果我将其更改为重定向规则,则一切正常。我在这里缺少什么吗?
提前致谢。
I've set up a simple rule to rewrite all requests to my domain:
<rule name="Rewrite Test" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="mydomain.com" />
</conditions>
<action type="Rewrite" url="http://mydomain.com/TestImage.jpg" appendQueryString="false" />
</rule>
With this enabled I receive a 404 error every time I access my domain. However if I change this to a redirect rule, everything works fine. Is there something I'm missing here?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Daniel 所解释的,您无法重写域(除非您使用 ARR 将 IIS 设置为反向代理)。您只能重写到同一站点上的另一个 URL,因此它将隐式重写到原始请求所在的同一域。
您的重写规则应该是:
如果该网站未绑定到提供其他内容的其他域名,您也可能会放弃规则的条件并使其变得更加简单:
重定向可以很好地与您的示例配合使用(当然) 将客户端重定向到同一域上的 URL,也重定向到另一个域上的 URL。
As Daniel explains, you can't rewrite to a domain (unless you set up IIS as a reverse proxy with ARR). You can only rewrite to another URL on the same site and thus it will implicitly be rewritten the same domain that the original request was to.
Your rewrite rule should be:
If the site is not bind to other domain names that serve up other content you could potentially also drop the condition of the rule and make it even simpler:
A redirect works fine with your example as you can (of course) redirect the client to a URL on the same domain but also to a URL on another domain.