【问题标题】:IIS 7 Redirect using regular expressionIIS 7 使用正则表达式重定向
【发布时间】:2013-03-30 04:50:16
【问题描述】:

我们目前有一个在子域 http://blog.domain.com 下运行的 wordpress 博客。该站点当前也通过反向代理运行,作为指向原始子域站点的 http://www.domain.com/blog。

目前两个站点都运行正常,但我们遇到的问题是我们希望子域站点重定向到反向代理站点而不是呈现。我们只希望站点呈现为 http://www.domain.com/blog。我一直在尝试在服务器 2008 机器上使用 IIS 7 中的 URL 重写。

我认为我遇到的问题与正则表达式有关。我尝试使用 -- ^(blog.)* -- 当我在 IIS 中测试它时,它返回它匹配 (blog.domainname.com) 但是当我在浏览器中打开它时网站本身不会重定向。我不确定我错过了什么。提前感谢您的帮助。

    <rewrite>
      <rules>
        <rule name="Main Rule" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php" /></rule>
        <rule name="wordpress" patternSyntax="Wildcard">
          <match url="*" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php" /> </rule>
        <rule name="redirect to /blog" enabled="false" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^(blog.)*" />
           <action type="Redirect" url="http:// www.domainname.com/blog" />
           <conditions logicalGrouping="MatchAny">
            <add input="{HTTP_HOST}" pattern="(.*)" />
          </conditions>
        </rule>
      </rules>
    </rewrite>

【问题讨论】:

    标签: regex iis


    【解决方案1】:

    问题可能是当您点击该 URL 时,您的重写规则没有运行。 确保它实际映射到该站点。

    抱歉,我刚刚注意到您的规则未启用:

    <rule name="redirect to /blog" enabled="false" patternSyntax="ECMAScript" stopProcessing="true">
    

    您必须将 enabled 属性修改为 True。

    【讨论】:

    • 我去更新了代码,以便启用规则并且站点仍然没有重定向。我包含的代码是站点根文件夹中的 web.config 文件。如何确认它已映射到该网站?
    • 我认为您当前的设置重定向了两次,一次从您的子域重定向到您的域,然后返回。您能否使用 fiddler 之类的工具检查它是否正在重定向?或者,如果你能把网站传给我,我可以帮你查一下。
    猜你喜欢
    • 1970-01-01
    • 2014-10-13
    • 1970-01-01
    • 2023-03-15
    • 2020-06-10
    • 2021-01-19
    • 1970-01-01
    • 2018-03-14
    • 1970-01-01
    相关资源
    最近更新 更多