2013-06-19 165 views
1

我无法弄清楚如何解决这个问题,URL重写:下面这个模式IIS重写URL

应用/(.*)

应该被重定向到应用程序/索引

网址.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文件现在,但是当我浏览到应用程序/ someurl,我得到一个错误,因为js文件的一个不能加载。我认为这是因为第一条规则不起作用。

你能帮忙吗?

+0

在什么条件下(S)应重定向被忽略?只有当在子文件夹和请求js文件或html文件? – cheesemacfly

+0

在请求应用程序文件夹以及子文件夹中的js文件和html文件时,应该忽略重定向 – Sam

回答

2

这是我落得这样做:

<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> 
+1

很确定如果只保留2个第一个条件,它应该按照您的预期工作。 – cheesemacfly

+0

确实,你是对的,谢谢! – Sam