2013-06-19 174 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