且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

设置特定域的URL重写规则

更新时间:2022-11-26 17:28:29

我认为以下方法应该有效:

I think the following should work:

<rule name="mydomain.com" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^(mydomain\.com|www\.mydomain\.com)$" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    </conditions>
    <action type="Redirect" url="http://localhost/MyVDir/{R:1}" redirectType="Temporary" />
</rule>

任何URL上的匹配均确保检查条件,并且HTTP_HOST服务器变量似乎是检查请求的主机名的最可靠方法.您可以删除REQUEST_FILENAME输入条件,但可以很好地进行检查以确保始终提供静态文件.

The match on any URL makes sure the conditions are checked, and the HTTP_HOST server variable seems the most reliable way of checking the requested hostname. You could remove the REQUEST_FILENAME input condition, but it works as quite a nice sanity check to make sure static files are always served.