Redirect IIS URL重写(重定向)
我想在我的URL中将“索引”替换为“主页”,例如:Redirect IIS URL重写(重定向),redirect,iis,url-rewriting,web-config,Redirect,Iis,Url Rewriting,Web Config,我想在我的URL中将“索引”替换为“主页”,例如: www.mywebsite.com/index应重定向至www.mywebsite.com/home www.mywebsite.com/index/contact到www.mywebsite.com/home/contact等等 我试着应用这个规则 <rule name="Replace index" stopProcessing="true"> <match url="(.*)(/index)(.*)" />
www.mywebsite.com/index
应重定向至www.mywebsite.com/home
www.mywebsite.com/index/contact
到www.mywebsite.com/home/contact
等等
我试着应用这个规则
<rule name="Replace index" stopProcessing="true">
<match url="(.*)(/index)(.*)" />
<action type="Redirect" url="localhost:6782/home{R:3}" />
</rule>
以下是我问题的答案:
<rules>
<rule name="Redirect to home" stopProcessing="false">
<match url="^index(.*)" />
<action type="Redirect" url="home{R:1}" redirectType="Permanent" />
</rule>
</rules>
提示:尝试不同的规则(或使用匿名模式)时,请确保清除浏览器的缓存在match
标记中传递的用于匹配URL
的URL将是索引
或索引/联系人
,因此请自问是否提供了有效的正则表达式。这是正确的,以及“something.com/index/something other”。那为什么它不起作用呢?在您的例子中,错误只是您选择的正则表达式(.*)(/index)(.*)
。/
之前的索引
阻止它匹配任何请求IIS传递,就像我上面评论的那样。测试正则表达式的方法也不会有帮助,因为您的输入与IIS的行为不匹配。虽然这是一个非常常见的错误,但奇怪的是,微软从未试图改进IIS管理器来防止这种情况。