某客户将其网站内容放在其网站的子文件夹中,例如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地址,是否可以将重定向更改为自动重定向到www.customersite.com/?p=12 ?如果有,那是怎么回事?
谢谢!
我现在无法测试它,但这应该可以工作:
<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>
任何为www.customersite.com/content/?p=12的文件实际上都是IIS中的默认页面之一,因此该页面实际上类似于www.customersite.com/content/index.aspx?p=12,假设您的默认文件是index。Aspx可以是默认值等
只需在此位置添加一个文件,并设置后面的代码以获取查询字符串并进行重定向,您也可以从后面的代码更改标题状态以显示这是301。