【问题标题】:IIS 301 Redirect from subfolder to root folderIIS 301 从子文件夹重定向到根文件夹
【发布时间】:2011-12-20 21:52:37
【问题描述】:

客户将其网站内容放在其网站的子文件夹中,例如www.customersite.com/content。它已被移至根文件夹,例如www.customersite.com

我们在站点配置中添加了 IIS 301 重定向,如下所示:

<rewrite>
  <rules>
   <rule name="Redirect to Root" stopProcessing="true">
     <match url=".*" />
       <conditions>
        <add input="{HTTP_HOST}" pattern="^customersite.com/content/$" />
       </conditions>
      <action type="Redirect" url="http://www.customersite.com/{R:0}"
        redirectType="Permanent" />
   </rule>
  </rules>
</rewrite>

该网站的链接看起来像 www.customersite.com/content/?p=12 如果用户在旧的 www.customersite.com/content/?p=12 地址?如果有怎么办?

谢谢!

【问题讨论】:

    标签: iis redirect http-status-code-301


    【解决方案1】:

    我现在无法对其进行测试,但这应该可以:

    <rewrite>
      <rules>
       <rule name="Redirect to Root" stopProcessing="true">
         <match url="^content/(.*)" />
           <conditions>
            <add input="{HTTP_HOST}" pattern="^(www\.)?customersite.com$" />
           </conditions>
          <action type="Redirect" url="http://{C:0}/{R:1}" redirectType="Permanent" />
       </rule>
      </rules>
    </rewrite>
    

    【讨论】:

      【解决方案2】:

      任何 www.customersite.com/content/?p=12 的文件实际上都是 IIS 中的默认页面之一,所以该页面真的类似于 www.customersite.com/content/index.aspx? p=12 假设您的默认文件是 index.aspx 它可能是默认文件等。

      只需在此位置添加一个文件并设置后面的代码以获取查询字符串并进行重定向,您还可以从后面的代码中更改标头状态以显示这是一个 301。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-12-03
        • 1970-01-01
        • 2011-10-01
        • 1970-01-01
        • 2015-10-06
        • 2019-08-28
        • 2014-07-19
        • 1970-01-01
        相关资源
        最近更新 更多