2011-07-20 83 views
2

我想要的是將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重寫功能來實現這一點。

+0

也許[this](http://stackoverflow.com/questions/278668/is-it-possible-to-make-an-asp-net-mvc-route-based-on-a-subdomain)有幫助嗎? –

回答

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(poo.example.com)沒有真正需要在規則中指定它 - IIS將自動放入當前域。

+0

內的主機url。非常感謝。非常好 – tugberk

4

您可以在IIS中添加home.ashx作爲默認文檔(確保它出現在列表頂部),那麼您不需要做任何URL重寫。

+0

試過,沒有工作。我的應用程序是一個asp.net mvc應用程序,我認爲默認文檔因此無效。 – tugberk

+0

如果你直接請求'/ home.ashx',它會工作嗎?檢查請求是否被你的某條路由拾取,如果是,請在映射其他路由之前忽略對'.ashx'文件的請求:'IgnoreRoute(「{handler} .ashx?{* path}」 );' – wsanville

+0

是的,它的工作原理。你沒有得到我的問題。我需要一個正則表達式代碼來獲取匹配節點 – tugberk