Myster
Myster

Reputation: 18114

urlrewritING.net query character in virtual url causing redirect loop

I've got a project where we're re-building a site for a client, the new site is using umbraco on the .net platform. the old site was cold fusion.

Umbraco utilises the urlrewriting.net library so I created all the 301 recirect rules for the old cold fusions urls but this one is causing an infinite loop.

    <add name="r66" virtualUrl="^~/thing_info/index.cfm.D413249D-BCD8-304B-02CD-561DAC70641E$"
                destinationUrl="~/about-us/award-winning-product" redirect="Application" redirectMode="Permanent" ignoreCase="true" />

I know "." has a special meaning but it works well enough, also I've used "." to match any character including the "?" character beginning the query string. if I visit try the url without a querystring like so

http://staging.site/thing_info/index.cfm-D413249D-BCD8-304B-02CD-561DAC70641E

then I get redirected correctly to

http://staging.site/about-us/award-winning-product

However if I try the url (question mark is the only difference)

http://staging.site/thing_info/index.cfm?D413249D-BCD8-304B-02CD-561DAC70641E

Then I end up in a redirect loop to itself. (I checked the response header)

Does anyone have any idea if I've done something wrong or if it's a bug in the urlrewriting.net library? or how to correct the problem?

Upvotes: 3

Views: 2447

Answers (3)

brodie
brodie

Reputation: 5434

I had the same problem when trying to do a permanent 301 redirect using umbraco and UrlRewritingNet.

After reading this and some hair pulling I got it working with the following entry in umbraco/config/urlrewriting.config

<add name="Rule1885"
      virtualUrl="^~/whats-on/event\.aspx\?id=1885"
      destinationUrl="~/whats-on/event.aspx?id=1822"
      rewriteUrlParameter="IncludeQueryStringForRewrite"
      redirectMode="Permanent"
      redirect="Application"   
      ignoreCase="true" />

It was the combination of Jonathan's answer, to add rewriteUrlParameter="IncludeQueryStringForRewrite", and escaping the virtualUrl parameter correctly that sorted it out.

Upvotes: 2

Jonathan Stanton
Jonathan Stanton

Reputation: 2660

By default UrlRewritingNet will not include the querystring in the pattern match. to enable this you need to add the following attribute rewriteUrlParameter="IncludeQueryStringForRewrite"

<add name="r66" virtualUrl="^~/thing_info/index.cfm.D413249D-BCD8-304B-02CD-561DAC70641E$"
     destinationUrl="~/about-us/award-winning-product" redirect="Application" redirectMode="Permanent" 
     ignoreCase="true" rewriteUrlParameter="IncludeQueryStringForRewrite" />

Give this a try and let me know if it works.

Jonathan

Upvotes: 5

BeaverProj
BeaverProj

Reputation: 2215

Its a regular expression so the . means any character. You could try escaping the dot with . or the question with \? to match that character specifically.

Upvotes: 2

Related Questions