【问题标题】:Redirect home page重定向主页
【发布时间】:2011-07-21 10:04:46
【问题描述】:

我想要将poo.example.com 重定向到poo.example.com/home.ashx,但我使用以下代码失败了;

<rewrite>
  <rules>
    <rule name="Redirect to HTTPS" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
    </rule>
    <rule name="Redirect poo.example.com to poo.example.com/home.ashx" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="(./)" />
      <action type="Redirect" url="https://{HTTP_HOST}/home.ashx" />
    </rule>
  </rules>
</rewrite>

我使用的是 IIS 7.5。

注意

我厌倦了使用默认文档,但它不起作用。我的应用程序是一个 asp.net mvc 应用程序。它可能与此有关,但这在这里不是问题。我需要使用 IIS URL 重写功能来实现它。

【问题讨论】:

  • 也许this 有帮助?

标签: asp.net regex iis iis-7 url-rewriting


【解决方案1】:

您可以在 IIS 中将home.ashx 添加为默认文档(确保它出现在列表顶部),然后您就不需要进行任何 URL 重写。

【讨论】:

  • 试过了,没用。我的应用程序是一个 asp.net mvc 应用程序,我想默认文档因此无法正常工作。
  • 直接请求/home.ashx是否有效?检查请求是否被您的一条路由接收,如果是,请在映射其他路由之前尝试忽略对 .ashx 文件的请求:IgnoreRoute("{handler}.ashx?{*path}");
  • 是的,它有效。你没有得到我的问题。我需要一个正则表达式代码来获取匹配节点内的主机 url
【解决方案2】:

这将重写(当URL在浏览器中保持不变时内部重定向):

<rule name="home.ashx" stopProcessing="true">
    <match url="^$" />
    <action type="Rewrite" url="/home.ashx" />
</rule>

这将重定向(301 永久重定向):

<rule name="home.ashx" stopProcessing="true">
    <match url="^$" />
    <action type="Redirect" url="/home.ashx" />
</rule>

由于源 URL 和目标 URL (poo.example.com) 中的域名相同,因此无需在规则中指定它——IIS 会自动放置当前域。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-14
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-17
    相关资源
    最近更新 更多