问题
I am trying to figure out the best URL rewrite rule to accomplish the following.
http://intranet/sites/default.aspx rewrite to http://intranet.domain.com/sites/default.aspx
http://intranet rewrite to http://intranet.domain.com
Also in IIS the URL binding is set to "intranet" for that web application
Hope that makes sense. Can someone please help with the rewrite rule?
回答1:
This is the rule I would use:
<rule name="Intranet redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^intranet$" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="http://intranet.domain.com/{R:0}" />
</rule>
It will match any requested path (url="(.*)"
) on the host exactly named http://intranet
(pattern="^intranet$"
and with https
been turned off) and redirect it to http://intranet.domain.com/{R:0}
(where {R:0}
is a back reference containing whatever path was requested).
来源:https://stackoverflow.com/questions/18006963/iis-url-rewrite-for-redirect-to-fqdn