IIS 301从子文件夹重定向到根文件夹

时间:2011-11-03 06:07:44

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

客户的网站内容位于其网站上的子文件夹中,例如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/?p=12旧的www.customersite.com/content/?p=12地址?如果是这样的话?

谢谢!

2 个答案:

答案 0 :(得分:3)

我现在无法测试它,但这应该有效:

<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>

答案 1 :(得分:0)

任何www.customersite.com/content/?p=12的文件实际上都是IIS中的默认页面之一,因此页面真的会像www.customersite.com/content/index.aspx一样? p = 12假设您的默认文件是index.aspx,它可能是默认文件等。

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

相关问题