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

发布于 2024-12-13 13:17:22 字数 747 浏览 1 评论 0原文

客户将其网站内容放在其网站的子文件夹中,例如 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?如果是这样怎么办?

谢谢你!

A customer had their website content in a subfolder on their site e.g. www.customersite.com/content. It has since been moved to the root folder e.g. www.customersite.com

We've added a IIS 301 redirect, to the site config that looks like this:

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

The site had links that looked like www.customersite.com/content/?p=12 would it be possible to change the redirect to automatically redirect to www.customersite.com/?p=12 if a user types in the old www.customersite.com/content/?p=12 address? If so how?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

舞袖。长 2024-12-20 13:17:22

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

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

I'm not able to test it right now, but this should work:

<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>
时光无声 2024-12-20 13:17:22

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

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

Any file which is www.customersite.com/content/?p=12 will actually be one of the default pages in IIS, so the page will really be something like www.customersite.com/content/index.aspx?p=12 assuming your default file is index.aspx it could be default etc.

Just add a file at this location and set the code behind to take the query string and do a redirect, you can also change the header state from the code behind to show this is a 301.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文