Chr*_*sic 25 iis-7 url-rewriting iis-7.5
使用IIS URL Rewrite从URL中删除www子域的最佳方法是什么?
Jan*_*nen 36
如果您希望它与任何主机名一起使用(不将其硬编码到规则中),您需要执行以下操作:
<rule name="Remove www" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
</conditions>
<action type="Redirect" url="http://{C:1}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)
在重定向操作中,{C:1}包含条件中的第二个捕获组,而{R:0}包含规则中的任何内容(路径).appendQueryString ="true"还会将任何查询字符串附加到重定向(如果存在).但请记住,任何url哈希值(如果存在)都将在此过程中丢失,因为它们不会传递给服务器.
以下一个应该工作:
<system.webServer>
<rewrite>
<rules>
<rule name="Remove WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
</conditions>
<action type="Redirect" url="http://www.example.com{PATH_INFO}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13593 次 |
| 最近记录: |