简体   繁体   English

URL重写规则(iis):仅重定向www.example.com和www.example.com/default.aspx

[英]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.

相关问题 如何在 WordPress 网站中从 www.example.com/2020/70 到 www.example.com 中删除 URL? - How to Remove URL from www.example.com/2020/70 to www.example.com in a WordPress website? 网址重新打印从www.example.com到www.example.com/beta - URL rewrinting from www.example.com to www.example.com/beta 在网址中显示用户名……www.example.com/JoeMason - displaying username in url… www.example.com/JoeMason “ www.example.com/#/bar/1”是什么类型的URL? - What type of URL is “www.example.com/#/bar/1”? URL重写从www.example.com/blog/blog.php到www.example.com/blog/ - URL rewriting going from www.example.com/blog/blog.php to just www.example.com/blog/ 如何将诸如 www.example.com/m/a1 之类的 wordpress 类别 url 修改为 www.example.com/category/m/a1 - how to modified wordpress category url like www.example.com/m/a1 to www.example.com/category/m/a1 example.com和www.example.com被视为不同的会话 - example.com and www.example.com are treated as different sessions 为什么将“ ///www.example.com”视为绝对URI? - Why “///www.example.com” is treated as an absolute URI? 如何创建网址,例如www.example.com/EN/login - How to create URLs like www.example.com/EN/login 如何将我的URL像www.example.com/profile.php?id=xyz转换为www.example.com/xyz? - How do i convert my URL's like www.example.com/profile.php?id=xyz into www.example.com/xyz?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM