简体   繁体   English

创建Url重写到域-ASP.NET \\ IIS 7

[英]Creating Url Rewrite to a domain - ASP.NET \ IIS 7

I'm using ASP.NET 3.5 with IIS 7 with the URL Rewrite Module 2.0 installed. 我正在将ASP.NET 3.5与IIS 7一起使用,并安装了URL重写模块2.0。

When I create the first test rewrite rule: 当我创建第一个测试重写规则时:

    <rewrite>
        <rules>
            <rule name="Test rule1" patternSyntax="ExactMatch">
                <match url="w/123/test" />
                <action type="Rewrite" url="article.aspx?id=123" />
            </rule>           
        </rules>
    </rewrite>

It works perfectly (http://www.myapp.com/w/123/test -> http://www.myapp.com/article.aspx?id=123 ). 它可以完美运行(http://www.myapp.com/w/123/test-> http://www.myapp.com/article.aspx?id=123 )。

BUT, when I try to use it on a domain that I own, it doesn't work. 但是,当我尝试在自己拥有的域上使用它时,它将无法正常工作。 I assume that something in my syntax is wrong. 我认为我的语法有误。 Here is what i'm trying to do: 这是我想做的事情:

            <rule name="Test Rule2" patternSyntax="ExactMatch">
                <match url="http://www.my-domain.com" />
                <action type="Rewrite" url="article.aspx?id=123" />
            </rule> 

When I try to browse http://www.my-domain.com I expect to be redirected to the article.aspx page, which I don't, I just get 404 page not found. 当我尝试浏览http://www.my-domain.com我希望将其重定向到article.aspx页面,但我没有找到404页面。

How should I write a rule for a domain and not for a path ? 我应该如何为域而不是路径编写规则?

Thanks in advance, Gal. 预先感谢,加尔。

Rules are relative to the place where the web.config lives. 规则是相对于web.config所在的位置的。 You don't need to specify any domain for your rule. 您无需为规则指定任何域。 The input for your /> is going to be always the URL Path without the query string and without leading slash. />的输入将始终是URL路径,没有查询字符串,也没有前导斜线。 That means, if you request "http://www.my-domain.com/" the input is going to be "". 这意味着,如果您请求“ http://www.my-domain.com/”,则输入将为“”。 If you request "http://www.my-domain.com/w/123/test", the input would be "w/123/test". 如果您请求“ http://www.my-domain.com/w/123/test”,则输入为“ w / 123 / test”。

If you just browse to http://www.my-domain.com/ " the "Default Document" module in IIS will try to rewrite your request to something like http://www.my-domain.com/default.html " and that won't match your rule. 如果您只是浏览到http://www.my-domain.com/ ,则IIS中的“默认文档”模块将尝试将您的请求重写为类似http://www.my-domain.com/default.html的内容 ”,这与您的规则不符。 Make sure to disable default document module. 确保禁用默认文档模块。

If that doesn't work, URL Rewrite has a tracing feature where you can see step-by-step the workflow: 如果这不起作用,则URL Rewrite具有跟踪功能,您可以在其中逐步查看工作流程:

http://learn.iis.net/page.aspx/467/using-failed-request-tracing-to-trace-rewrite-rules/ http://learn.iis.net/page.aspx/467/using-failed-request-tracing-to-trace-rewrite-rules/

NB For server rules, the input URL includes leading slash always. 注意对于服务器规则,输入URL始终包含前导斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM