Web 配置规则中通配符 URL 的 301 重定向
301 redirection for wildcard urls in webconfig rules
我尝试了很多...我没有得到要重定向的域
301 重定向到通配符 URL
我有https://www.example.com/blog wild card - https://blog.example.com/
我需要重定向域 https://www.example.com/blog to this one https://blog.example.com/
/博客到 https://blog.example.com/
<rule name="Redirect blog" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="/blog$" />
</conditions>
<action type="Redirect" url="https://blog.example.com/" redirectType="Permanent"/>
</rule>
您可以使用 {PATH_INFO} 代替 {HTTP_HOST}
<rule name="Redirect blog" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{PATH_INFO}" pattern="/blog$" />
</conditions>
<action type="Redirect" url="https://blog.example.com/" redirectType="Permanent"/>
</rule>
如果只想匹配blog结尾的,可以试试下面的规则:
<rule name="Redirect blog" stopProcessing="true">
<match url="^blog(/)?(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" />
</conditions>
<action type="Redirect" url="https://blog.example.com/{R:2}" />
</rule>
如果你想全部匹配,那么你可以试试这个规则:
<rule name="Redirect blog" stopProcessing="true">
<match url="^blog(/)?(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" />
</conditions>
<action type="Redirect" url="https://blog.example.com/" />
</rule>
我找到了解决方案
<rule name="Blog Redirect" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?example.com$" />
<add input="{REQUEST_URI}" pattern="^/blog$" />
</conditions>
<action type="Redirect" url="https://blog.example.com" appendQueryString="false" redirectType="Permanent" />
</rule>
我尝试了很多...我没有得到要重定向的域
301 重定向到通配符 URL
我有https://www.example.com/blog wild card - https://blog.example.com/
我需要重定向域 https://www.example.com/blog to this one https://blog.example.com/
/博客到 https://blog.example.com/
<rule name="Redirect blog" stopProcessing="true"> <match url=".*" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <add input="{HTTP_HOST}" pattern="/blog$" /> </conditions> <action type="Redirect" url="https://blog.example.com/" redirectType="Permanent"/> </rule>
您可以使用 {PATH_INFO} 代替 {HTTP_HOST}
<rule name="Redirect blog" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{PATH_INFO}" pattern="/blog$" />
</conditions>
<action type="Redirect" url="https://blog.example.com/" redirectType="Permanent"/>
</rule>
如果只想匹配blog结尾的,可以试试下面的规则:
<rule name="Redirect blog" stopProcessing="true">
<match url="^blog(/)?(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" />
</conditions>
<action type="Redirect" url="https://blog.example.com/{R:2}" />
</rule>
如果你想全部匹配,那么你可以试试这个规则:
<rule name="Redirect blog" stopProcessing="true">
<match url="^blog(/)?(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" />
</conditions>
<action type="Redirect" url="https://blog.example.com/" />
</rule>
我找到了解决方案
<rule name="Blog Redirect" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?example.com$" />
<add input="{REQUEST_URI}" pattern="^/blog$" />
</conditions>
<action type="Redirect" url="https://blog.example.com" appendQueryString="false" redirectType="Permanent" />
</rule>