开发者

IIS UrlRewrite problem

开发者 https://www.devze.com 2023-01-24 12:52 出处:网络
I\'ve been using the UrlRewrite IIS plugin for about a month on our production site. I created a single redirect rule using the supplied template/wizard, the resulting config enrty is as follows:

I've been using the UrlRewrite IIS plugin for about a month on our production site.

I created a single redirect rule using the supplied template/wizard, the resulting config enrty is as follows:

<rewrite>
    <rules>
        <rule name="CanonicalHostNameRule1" enabled="true">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^www\.mycompany\.com$" negate="true" />
            </conditions>
            <action type="Redirect" url="http://www.mycompany.com/{R:1}" />
        </rule>
    </rules>
</rewrite>

It's been running fine until this morning, when the site started erroring with "too many redirects". As far as I know, nothing in the configuration or infrastructure cha开发者_Python百科nged.

I disabled the rule, and the site became functional again (though clearly without any redirecting).

I then re-enabled the rule, and now all is running as expected. I didn't make any changes to the rule other than to temporarily disable it.

Any ideas? Is the plugin buggy?


I'd recommend setting this up:

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

This may help you track down the problem if you start getting the "too many directs" error again.


Try this other code, i have on my web and run perfect:

<rule name="Canonical Host Name" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^yourdomain\.com$" />
    </conditions>
        <action type="Redirect" url="http://www.yourdomain.com/{R:0}" redirectType="Permanent" />
    </rule>

The explanation is simple: Match any URL received to process The condition is that have anydomaintext.extension (your domain and extension) without prefix Redirect to same domain with full prefix and put all url.

Other tries was R:1 but quit some of the main url and not run. The sample from Ruslani: http://blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx I tried to use adding www but finally use the sample above.


The fix below worked for me. I discovered my rewrite rule was at out-of-date. The other domain had changed their URL policy and were now redirecting all traffic from otherdomain.com to www.otherdomain.com

<action type="Rewrite" url="http://otherdomain.com/abc/{R:1}" />

to

<action type="Rewrite" url="http://www.otherdomain.com/abc/{R:1}" />

Do you see the difference? By adding the 'www' I preempted the other domain redirection. I basically just complied with their new policy.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号