【问题标题】:Redirect from subfolder to new domain?从子文件夹重定向到新域?
【发布时间】:2019-07-12 14:28:39
【问题描述】:

我不知道 ASP.NET。我最近开始学习 PHP。但是我遇到了 IIS 托管的问题。其实这不是问题,这是我想做的事情。我在这里检查并谷歌应用了不同的规则,但它确实对我有用。所以在这里我请求你们的帮助。

能否请您为我的 web.config 写一条规则。

我需要从子文件夹到新域的 301 重定向。

这里的样子

domain.com/folder/* ----> newdomain.com 

提前感谢您!

我尝试了不同的规则,尝试使其适应我的需要,但没有成功。

【问题讨论】:

标签: asp.net iis url-rewriting iis-7 url-rewrite-module


【解决方案1】:

以下规则实现了您所描述的重定向。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Test" stopProcessing="true">
          <match url="folder/(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain.com$" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="http://newdomain.com" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
  • &lt;match url="folder/(.*)" /&gt; 部分将检查 URL 并匹配所有以 folder/ 开头的请求。
  • &lt;add input="{HTTP_HOST}" pattern="^domain.com$" /&gt; 将匹配顶级域
  • &lt;action type="Redirect" url="http://newdomain.com" /&gt; 指定请求将重定向到哪里
  • redirectType="Permanent" 会将重定向的状态码设置为 301。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-12
    • 2023-03-09
    • 1970-01-01
    • 2012-09-17
    • 2013-01-20
    • 1970-01-01
    • 2016-12-17
    相关资源
    最近更新 更多