Copied to clipboard

Flag this post as spam?

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


  • Luuk Krijnen 12 posts 66 karma points
    Sep 02, 2014 @ 09:58
    Luuk Krijnen
    0

    Url rewriting trailing slash fail

    Hi all,

    i'm struggling with the url rewriting. I have a template called tournament.cshtml. Many links to our site are pointing to the domainname.nl/tournament/

    because there is no tournament with this link I've written en url rewrite rule as follows:

    <add name="tournaments"
      ignoreCase="true" 
      virtualUrl="~/tournament$"
      destinationUrl="~/tournaments/specificTournament" />
    

    this is working for http://www.domainname.nl/tournament but will give a 404 when adding a trailing slash like: http://www.domainname.nl/tournament/

    because I don't rely on my regex skills adding a second rule like the following doesn't help.

    <add name="tournamentsextra"
      ignoreCase="true" 
      virtualUrl="~/tournament/$"
      destinationUrl="~/tournaments/specificTournament" />
    

    What am I doing wrong?

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Sep 02, 2014 @ 11:20
    Sebastiaan Janssen
    100

    Well the first rule is processed first, so I think if you just switch them around it should work.

    But to make your example simpler you could just add a ? after the slash which in regex means: match between 0 and 1 of the preceding token. Exactly what you want: match if there is 0 or 1 slash. And then you only need one rule:

    <add name="tournamentsextra"
      ignoreCase="true" 
      virtualUrl="~/tournament/?$"
      destinationUrl="~/tournaments/specificTournament" />
    
  • Luuk Krijnen 12 posts 66 karma points
    Sep 03, 2014 @ 09:02
    Luuk Krijnen
    0

    Sebastiaan,

    can you explain (or give me a hint how to troubleshoot) why it is working in Chome, but I get an error when opening the same site in IE with a trailing slash (without it is working in IE). site: http://www.batswingers.nl/toernooi/

    Error:

    This page can’t be displayed
    
    •Make sure the web address http://www.batswingers.nl is correct.
    •Look for the page with your search engine.
    •Refresh the page in a few minutes.
    
    
    Fix connection problems
    
  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Sep 03, 2014 @ 09:30
    Sebastiaan Janssen
    0

    I don't know about that one.. sounds like a browser issue, it works fine in IE11 on my machine with and without slash..

Please Sign in or register to post replies

Write your reply to:

Draft