【问题标题】:IIS rewriting urlIIS 重写 url
【发布时间】:2013-06-16 06:01:08
【问题描述】:

我不知道如何通过 url 重写来解决这个问题:

遵循这种模式的网址

app/(.*)

应该被重定向到 app/index.cshtml

然而app文件夹包含子文件夹、js文件和html文件等资源。这些应该被忽略,不应该进行重定向。

我是这样做的:

 <rewrite>
  <rules>
    <rule name="Rule 1" stopProcessing="true">
      <match url="app/(.*/.js)" />
      <action type="None" />
    </rule>
    <rule name="Rule 2">
      <match url="app/(.*)" />
      <action type="Rewrite" url="app/index.cshtml" />
    </rule>

  </rules>
</rewrite>

我现在只尝试排除 js 文件,但是当我浏览到 app/someurl 时,我收到一个错误,因为其中一个 js 文件无法加载。我认为这是因为第一条规则不起作用。

你能帮忙吗?

【问题讨论】:

  • 在什么情况下应该忽略重定向?仅在子文件夹中并请求 js 文件或 html 文件时?
  • 在 app 文件夹和子文件夹中请求 js 文件和 html 文件时应忽略重定向

标签: iis url-rewriting


【解决方案1】:

这就是我最终做的:

<rule name="Rule1">
      <match url="(.*)" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{URL}" negate="true" pattern="\.axd$" />
        <add input="{URL}" negate="true" pattern="\.jpg$" />
        <add input="{URL}" negate="true" pattern="\.gif$" />
        <add input="{URL}" negate="true" pattern="\.png$" />
        <add input="{URL}" negate="true" pattern="\.css$" />
        <add input="{URL}" negate="true" pattern="\.ico$" />
        <add input="{URL}" negate="true" pattern="\.cur$" />
        <add input="{URL}" negate="true" pattern="\.js$" />
        <add input="{URL}" negate="true" pattern="\.xml$" />
        <add input="{URL}" negate="true" pattern="\.svg$" />
        <add input="{URL}" negate="true" pattern="\.ttf$" />
        <add input="{URL}" negate="true" pattern="\.eot$" />
        <add input="{URL}" negate="true" pattern="\.woff$" />
        <add input="{URL}" negate="true" pattern="\.html$" />
      </conditions>
      <action type="Rewrite" url="app/index.cshtml" />
    </rule>

【讨论】:

  • 很确定如果您只保留前两个条件,它应该可以按预期工作。
猜你喜欢
  • 2013-07-01
  • 2016-06-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多