[英]URL rewrite rule (iis): redirect ONLY www.example.com and www.example.com/default.aspx
I am trying to do a rewrite to redirect the following pages ONLY: 我正在尝试进行重写以仅重定向以下页面:
www.example.com/ www.example.com/
www.example.com/default.aspx www.example.com/default.aspx
I want to let all other requests pass through. 我想让其他所有请求通过。 I know I'm pretty close but I just can't seem to get it perfect. 我知道我已经很近了,但是我似乎无法完美。 Thanks in advance for any & all help! 在此先感谢您提供的所有帮助!
Here's what I have so far: 这是我到目前为止的内容:
<rewrite>
<rules>
<rule name="Base Redirect" stopProcessing="true">
<match url="" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" ignoreCase="true" negate="false" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="shop.example.com" appendQueryString="true" />
</rule>
<rule name="Default.aspx Redirect" stopProcessing="true">
<match url="default.aspx" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" ignoreCase="true" negate="false" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="shop.example.com" appendQueryString="true" />
</rule>
</rules>
</rewrite>
Problem is it's sending anything containing default.aspx (/pages/default.aspx, etc) and we don't want to redirect anything but the root level default.aspx. 问题是它正在发送包含default.aspx的任何内容(/pages/default.aspx等),我们只希望重定向根目录default.aspx之外的任何内容。
Felix 费利克斯
Try this (basically adding the "^" character to tell regex to only match when it is at the beginning: 尝试以下操作(基本上添加“ ^”字符以告诉正则表达式仅在开始时才匹配:
<rule name="Base Redirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^$" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" />
</conditions>
<action type="Redirect" url="http://shop.example.com/" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="Default.aspx Redirect" stopProcessing="true">
<match url="^default.aspx" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" />
</conditions>
<action type="Redirect" url="http://shop.example.com" appendQueryString="true" redirectType="Permanent" />
</rule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.