IIS URL重写的
问题描述:
我试图用IIS7 URL重写模块重写 services.mydomain.com/some-file-here到mydomain.webhost.com/folder/some-file-hereIIS URL重写的
的规则如下:
Pattern = ^services.mydomain.com/(.*)$
Action = Rewrite
Rewrite URL = http://mydomain.webhost.com/folder/{R:1}
的问题是IIS一直给我404没有发现错误。我一直坚持这个好几天了。有任何想法吗?
答
你有你的模式错了。它不应该包含域名或查询字符串 - 只有没有引导斜杠的路径。请参见下面的工作规则:
<rule name="MyRewriteRule" stopProcessing="true">
<match url="^(some-file-here)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^services\.mydomain\.com$" />
</conditions>
<action type="Redirect" url="http://mydomain.webhost.com/folder/{R:1}" />
</rule>
以上规则,如果主机名是services.mydomain.com
才会触发。如果你不需要这样的附加条件(这是可选的),然后就删除这些三线:<conditions>...</conditions>
而且,上述规则将只做一个特定的重定向从services.mydomain.com/some-file-here
到mydomain.webhost.com/folder/some-file-here
。如果您需要重定向任何类似的文件,请使用下面的文件:
<rule name="MyRewriteRule" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^services\.mydomain\.com$" />
</conditions>
<action type="Redirect" url="http://mydomain.webhost.com/folder/{R:1}" />
</rule>
URL重定向是否成功? 404在哪个页面上? – 2011-06-11 01:17:43
当我访问说services.mydomain.com/Hello,我得到了404.该网址似乎并没有重新定向。 – 2011-06-11 01:59:40