Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • J 447 posts 864 karma points
    Mar 07, 2017 @ 17:04
    J
    0

    Understanding Urlrewriting

    I have a search page which im trying to give friendly URLS to when an item is searched for. So added the below to my UrlRewriting

    <add name="SearchMain" virtualUrl="^~/search/" destinationUrl="/searchresults/?cid=1&amp;order=Asc" rewriteUrlParameter="ExcludeFromClientQueryString" ignoreCase="true" />
    <add name="SearchCustom" virtualUrl="^~/search/(.*)/" destinationUrl="/searchresults/?cid=1&amp;order=Asc&amp;item=$1" rewriteUrlParameter="ExcludeFromClientQueryString" ignoreCase="true" />
    

    The plan is when a standard search is performed it should run SearchMain and when an item is searched for, SearchCustom should run.

    For some reason SearchMain always runs even though my query URL is /search/computers (computers being the search value)

    Where am i going wrong?

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Mar 08, 2017 @ 10:42
    Michael Latouche
    100

    Hello J,

    I am absolutely not an expert in this but by analogy with mvc routing: did you try to invert the two rules?

    Because actually your request "/search/computers" matches both SearchMain and SearchCustom, so I guess it probably takes the first matching rule it finds, which in your case is SearchMain...

    If you invert the rules, it will first try to match the SearchCustom, and only if there is no match, it will go further and check on SearchMain.

    Hope it helps.

    Cheers,

    Michaƫl.

  • J 447 posts 864 karma points
    Mar 08, 2017 @ 16:57
    J
    0

    THANK YOU!! this wasted 1 day of my time and inverting the order resolved the issue. Many thanks

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Mar 09, 2017 @ 00:01
    Michael Latouche
    0

    Great! Glad I could help :-)

Please Sign in or register to post replies

Write your reply to:

Draft