redirect - 301 使用 web.config 将一个域重定向到另一个域

标签 redirect iis web-config umbraco http-status-code-301

我有多个域指向一个托管位置。
我希望将其中一个域建立为我的主域,因此我希望在用户从辅助域访问我的站点时执行 301 重定向到该主域。

例如:

www.example.com

这是我的主域。我希望与我的网站关联的所有其他域都重定向到这里。

如果用户进来:

www.test.com 或
www.test.com/anypage
等等。

然后我希望用户被重定向到该页面的示例版本。

如何使用应用程序的 web.Config 文件执行此操作?我问的原因是,通常我的网络托管服务提供商在他们的后台有一个工具,允许我设置此重定向,但是,我们的客户选择了不提供此类工具的其他托管服务提供商。

我尝试使用以下代码进行此重定向,但似乎不起作用:

<rule name="Canonical Host Name" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTP_HOST}" negate="true" pattern="^test\.com$" />
  </conditions>
  <action type="Redirect" url="http://www.example.com/{R:1}}" redirectType="Permanent" />
</rule>

我的应用程序是一个 Umbraco 驱动的站点,因此在 web.config 文件中有几个 system.webServer 条目。可能只是我在错误的地方输入了这段代码,但这里的任何帮助将不胜感激,因为我只习惯于在 .htaccess 文件中进行 301 重定向。

最佳答案

这并不是真的与 umbraco 相关,但我认为您想要做的是:

<rewrite>
  <rules>
    <rule name="redirect" enabled="true">
      <match url="(.*)" />
        <conditions>
          <add input="{HTTP_HOST}" negate="true" pattern="^www\.example\.com$" />
        </conditions>
      <action type="Redirect" url="http://www.example.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

匹配所有 url,除非主机名部分恰好是 www.example.com - 并将它们重定向到 www.example.com/whatever。

关于redirect - 301 使用 web.config 将一个域重定向到另一个域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32648449/

相关文章:

php - 如何在没有任何 SSL 证书的情况下将 https 重定向到 http

Apache 重定向网址

c# - Visual Studio :Could not create SSL/TLS secure channel

c# - 如何使用 C# 从虚拟目录创建 HTTP 重定向

security - IIS7,web.config 仅允许静态文件处理程序位于网站的目录/上传中

.net - web.config 转换 - appSettings 节点不转换

asp.net - 从 web.config 引用 App_Code 中的代码

redirect - IIS 将 www 重定向到非 www 并将 http 重定向到 https : is it possible to do it with only one Redirect?

javascript - html 按钮重定向到 &lt;input&gt; 中指定的页面

.net - 有没有办法运行完全独立的 ASP.NET 1.1 Web 应用程序(没有 IIS 或 SQL Server)?