2011-07-20 77 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