Search code examples
asp.netumbraco

debugging Url rewriting in umbraco


I have a url rewrite rule specified for my umbraco site like:

<add name="circuitdetail" 
    virtualUrl="^~/circuits/(.*).aspx" 
    rewriteUrlParameter="ExcludeFromClientQueryString" 
    destinationUrl="~/circuits/detail.aspx?circuit=$1" 
    ignoreCase="true" />

I would like the /circuits/albert-park to be mapped to /circuits/detail?circuit=albert-park.
When I enter that second url I correctly get the desired page but when I enter the first, I get my 404 page.

In Umbraco I have a page named "Circuits" and nested underneath it is the page named Detail. As described above, entering the unfriendly url works but it seems the url rewrite is not working.

What am I doing wrong?


Solution

  • It looks as if your RegEx is matching the destinationURL as well as the VirtualURL.

    So when it re-writes to ~/circuits/detail.aspx?circuit=$1

    This is also being matched by the ^~/circuits/(.*).aspx RegEx.

    Adding a $ to the end of your RegEx should fix it. The $ tells the RegEx to match up to the end of the line.

    i.e.

    ^~/circuits/(.*).aspx$
    

    More info: http://www.regular-expressions.info/anchors.html