Copied to clipboard

Flag this post as spam?

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


  • DavidDBD 3 posts 23 karma points
    Jun 05, 2023 @ 15:36
    DavidDBD
    0

    Rewriting URL to mask query string in umbraco 11.

    I have a render mvc controller (/Test/)

    That page has a query string parameter passed into it (/Test/?number=123) and in the overridden index action I have

    var number = ControllerContext.Request.Query["number"]

    What I would like to do is mask that query string param from the users so they just see /Test/123

    If this was a normal MVC project I'd just stick a route attribute on the action, but that doesnt work in this case.

    Any ideas?

  • jonok 297 posts 658 karma points
    Jun 14, 2023 @ 01:31
    jonok
    0

    You can add a rule to the 'rewrite' section of the web.config, something like this:

    <rule name="^Test/(.*)/" stopProcessing="true">
      <match url="^Test/(.*)/" />
      <action type="Rewrite" url="/Test/?number={R:1}" appendQueryString="false" />
    </rule>
    

    Let me know if you need help setting this up in the web.config in V11.

  • DavidDBD 3 posts 23 karma points
    Jun 15, 2023 @ 09:49
    DavidDBD
    0

    Hi

    Thanks for the response.

    I did something similar - its a .net 7 project and doesnt have any web.config files, We view XML config as a bit of a step backwards so dont want to go to the lengths of creating them for this.

    However as its just one rule and it will never need to change we implemented it in apps configure method when the web host is built :

    var rewriteOptions = new RewriteOptions().AddRewrite("(?i)XX/(.*)", "/xx?yy=$1", skipRemainingRules: true);
    
    app.UseRewriter(rewriteOptions);
    
Please Sign in or register to post replies

Write your reply to:

Draft