【问题标题】:How do I redirect my page with web.config如何使用 web.config 重定向我的页面
【发布时间】:2020-07-31 11:13:30
【问题描述】:

我想将我的网站主 tiptilepro.com 重定向到我的子目录 tiptilepro.com/pro/editor

我有这段代码,但它不起作用:

<rewrite>
  <rules>
    <rule name="Redirect to sub" stopProcessing="true">
      <match url="^*.tiptilepro.com$" ignoreCase="false" />
      <action type="Redirect" url="/tiptilepro.com/pro/editor" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

用户应该会看到子文件夹tiptilepro.com/pro/editor 的内容,但在地址栏中的主网址:tiptilepro.com

编辑: 我现在已经将if($_SERVER['HTTP_HOST']=="www.tiptilepro.com") header('Location: pro/editor'); 放在我的索引文件中,我可以让地址栏只显示“www.tiptilepro.com”吗?

【问题讨论】:

  • 你想重写还是重定向。这是两个不同的东西。
  • 我的内容在 pro/editor 文件夹中,我希望有 url tiptilepro.com 来显示内容。
  • 那么你不需要它们中的任何一个。然后你应该在你的应用程序中修复路由,以便它显示你真正想要的。

标签: azure redirect url-rewriting web-config


【解决方案1】:

试试这个:

<rewrite>
    <rules>
        <rule name="RedirectToNewURL" stopProcessing="false">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern="^(tiptilepro.com/)$" />
          </conditions>
          <action type="Redirect" url="https://tiptilepro.com/pro/editor" redirectType="Permanent" />
        </rule>
    </rules>
<rewrite>

但是您需要做的是在您的应用程序中修复您的路由。例如。在 .NET Core / MVC 中,您可以在 Startup.cs 文件中添加正确的路由。

            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=pro}/{action=editor}/{id?}");

【讨论】:

  • 出现内部服务器错误,无法显示页面。
猜你喜欢
  • 1970-01-01
  • 2017-12-04
  • 2021-09-14
  • 1970-01-01
  • 2019-09-08
  • 1970-01-01
  • 2012-04-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多