Copied to clipboard

Flag this post as spam?

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


  • Lev Nuznyy 19 posts 122 karma points
    Apr 22, 2019 @ 11:01
    Lev Nuznyy
    0

    pagination friendly url

    Hello

    Trying to make a beautiful url in page navigation But not how it does not work

    I have such a URL

    http: // localhost: 50554/xxxxxx/xxxxxxx/?page=1
    http: // localhost: 50554/xxxxxx/xxxxxxx/?page=1
    http: // localhost: 50554/хххххх/хххххх/хххххх/?page=1
    

    I know I need to use

    <rule />
    

    But I can't figure out how to do it.

    http: // localhost: 50554/xxxxxx/xxxxxxx/page1
    http: // localhost: 50554/xxxxxx/xxxxxxx/page1
    http: // localhost: 50554/хххххх/хххххх/хххххх/page1
    
  • Dennis Flæng Jørgensen 35 posts 145 karma points c-trib
    Apr 22, 2019 @ 13:15
    Dennis Flæng Jørgensen
    101
        <rule name="pagination" stopProcessing="true">
          <match url="(.+)/page([0-9]+)$" />
          <action url="{R:1}?page={R:2}" type="Rewrite" />
        </rule>
    

    Explanation:

    First we define which URLs we want to handle. In this case all URLs that end with page and then a number. We do that using Regex like this:

    <match url="(.+)/page([0-9]+)$" />
    

    We then tell IIS what we want to do with this request. In this case we rewrite (so we keep the url with e.x. "page4" in the URL. We then tell IIS how we want it to treat the URL. In this case we want it to treat it like its R1 (the first parentheses in the "<match url"-string). We then add the page-querystring-parameter with R2 (second parentheses in the "<match url"-string).

    <action url="{R:1}?page={R:2}" type="Rewrite" />
    

    This is a screenshot of a working sample in a normal .NET website (that's why i've added the ".aspx").

    enter image description here

    Hope this helps :)

  • Lev Nuznyy 19 posts 122 karma points
    Apr 23, 2019 @ 04:39
    Lev Nuznyy
    0

    I get a 404 error I understand that this will work in non umbraco

    enter image description here

  • Dennis Flæng Jørgensen 35 posts 145 karma points c-trib
    Apr 23, 2019 @ 07:22
    Dennis Flæng Jørgensen
    0
    <match url="(.+)/page([0-9]+)$" />
    

    This regex does not allow for traling slashes. Try: http://localhost50554/simvolika/page1

    If you prefer a trailing slash you could try this regex instead:

    <match url="(.+)/page([0-9]+)/?$" />
    
  • Lev Nuznyy 19 posts 122 karma points
    Apr 23, 2019 @ 08:11
    Lev Nuznyy
    0

    Thank you so much, it works great.

  • Lev Nuznyy 19 posts 122 karma points
    Apr 29, 2019 @ 08:02
    Lev Nuznyy
    0

    Hello I'm trying to rewrite the redirect rule for url http://localhost:50554/tags/teg-1/page2/

    <rule name="paginationTags" stopProcessing="true">
      <match url="^tags/([_0-9a-z-])/page([0-9]+)/?$" />
      <action url="tags/?tag={R:1}&amp;page={R:2}" type="Rewrite" />
    </rule>
    

    But I get error 404 What am I doing wrong ?

  • Dennis Flæng Jørgensen 35 posts 145 karma points c-trib
    Apr 29, 2019 @ 16:34
    Dennis Flæng Jørgensen
    0

    Hey Lev

    I think you're missing a "+" in your first group.

    <match url="^tags/([_0-9a-z-])/page([0-9]+)/?$" />
    

    should be:

    <match url="^tags/([_0-9a-z-]+)/page([0-9]+)/?$" />
    

    The plus sign tells the IIS that there should be 1 or more characters in the previous match - in your case that's the [_0-9a-z-]

    You can test the changes on one of the many online tools for checking regex-expressions. I recommend https://regexr.com/ - It also has a cheatsheet that tells you what the different characters mean.

  • Lev Nuznyy 19 posts 122 karma points
    Apr 30, 2019 @ 03:17
    Lev Nuznyy
    0

    Unfortunately, he still gives out 404

    <rule name="paginationTags" stopProcessing="true">
          <match url="^tags/([_0-9a-z-]+)/page([0-9]+)/?$" />
          <action url="tags/?tag={R:1}&amp;page={R:2}" type="Rewrite" />
    </rule>
    

    enter image description here

  • Amir Khan 1282 posts 2739 karma points
    Apr 29, 2019 @ 17:08
    Amir Khan
    0

    Dennis, thank you for explaining how this works. Super helpful, I've never been able to make sense of these querystring rewrites until now.

  • fatmazayed 41 posts 122 karma points
    Feb 04, 2024 @ 17:25
    fatmazayed
    0

    it's not work (i am using umbraco13)

  • fatmazayed 41 posts 122 karma points
    Feb 04, 2024 @ 18:32
    fatmazayed
    0

    i fixed it by doing following steps

    1. setting name of the document with space(if you need seperation use - or _)
    2. a class="dropdown-item" href="~/@(isEnglish?"":"ar/")Technologies/@item.Value">@item.Text in the url change id to be /

      old version was

    a class="dropdown-item" href="~/@(isEnglish?"":"ar/")[email protected]">@item.Text
    
    1. in the page that will dis[play the item to get slug

      var key = HttpContextAccessor.HttpContext.Request.RouteValues["slug"].ToString().Split('/')[1];
      

    key will be the get document name ( consider that item.value is document name

Please Sign in or register to post replies

Write your reply to:

Draft